如何在C#中将LPCWSTR编组为String?

CAR*_*OTH 5 c# pinvoke winapi

我正在尝试为以下方法定义P/Invoke签名(在中定义propsys.h)

PSSTDAPI PSRegisterPropertySchema(
    __in PCWSTR pszPath);
Run Code Online (Sandbox Code Playgroud)

我看到的WinNT.hPCWSTR是它的别名LPCWSTR

typedef __nullterminated CONST WCHAR *LPCWSTR, *PCWSTR;
Run Code Online (Sandbox Code Playgroud)

PSSTDAPI是别的HRESULT

那么该PSRegisterPropertySchema方法的P/Invoke签名应该如何呢?

CAR*_*OTH 8

设置CharSet值后,CharSet.Unicode它工作.

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

没有指定CharSet,函数返回的0x80070057E_INVALIDARG.