How to redirect LPCWSTR to String in C #?

I am trying to determine the P / Invoke signature for the following method (defined in propsys.h )

 PSSTDAPI PSRegisterPropertySchema( __in PCWSTR pszPath); 

I saw on WinNT.h that PCWSTR is an alias of LPCWSTR as

 typedef __nullterminated CONST WCHAR *LPCWSTR, *PCWSTR; 

And PSSTDAPI is an alias for HRESULT

So, how should the P / Invoke signature be for the PSRegisterPropertySchema method?

+4
source share
1 answer

After setting the CharSet value to CharSet.Unicode it worked.

 [DllImport("Propsys.dll", CharSet=CharSet.Unicode)] static internal extern int PSRegisterPropertySchema(String pszPath); 

Without specifying CharSet, the function returned 0x80070057 , which is equal to E_INVALIDARG .

+7
source

Source: https://habr.com/ru/post/1311786/


All Articles