开发者

How to marshall a LPCWSTR to String in C#?

开发者 https://www.devze.com 2023-01-02 09:47 出处:网络
I\'m trying to define a P/Invoke signature for the following method (defined in propsys.h) PSSTDAPI PSRegisterPropertySchema(

I'm trying to define a P/Invoke signature for the following method (defined in propsys.h)

PSSTDAPI PSRegisterPropertySchema(
    __in PCWSTR pszPath);

I've seen on the WinNT.h that PCWSTR is an alias to LPCWSTR as

type开发者_运维问答def __nullterminated CONST WCHAR *LPCWSTR, *PCWSTR;

And the PSSTDAPI is an alias for HRESULT

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


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

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

Without specifing the CharSet the function was returning 0x80070057 which is E_INVALIDARG.

0

精彩评论

暂无评论...
验证码 换一张
取 消