[英]How to marshall a LPCWSTR to String in C#?
我正在嘗試為以下方法定義P / Invoke簽名(在propsys.h
定義)
PSSTDAPI PSRegisterPropertySchema(
__in PCWSTR pszPath);
我在WinNT.h
看到PCWSTR
是LPCWSTR
的別名
typedef __nullterminated CONST WCHAR *LPCWSTR, *PCWSTR;
PSSTDAPI
是HRESULT
的別名
那么PSRegisterPropertySchema
方法的P / Invoke簽名應該如何呢?
將CharSet
值設置為CharSet.Unicode
之后就可以了。
[DllImport("Propsys.dll", CharSet=CharSet.Unicode)]
static internal extern int PSRegisterPropertySchema(String pszPath);
在沒有指定CharSet的情況下,函數返回0x80070057
,即E_INVALIDARG
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.