簡體   English   中英

如何在C#中將LPCWSTR編組為String?

[英]How to marshall a LPCWSTR to String in C#?

我正在嘗試為以下方法定義P / Invoke簽名(在propsys.h定義)

PSSTDAPI PSRegisterPropertySchema(
    __in PCWSTR pszPath);

我在WinNT.h看到PCWSTRLPCWSTR的別名

typedef __nullterminated CONST WCHAR *LPCWSTR, *PCWSTR;

PSSTDAPIHRESULT的別名

那么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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM