C#中與C++中的 LPWSTR(wchar_t *) 對應的類型


1.設置 CharSet = CharSet.Unicode

 [DllImport("test.dll", EntryPoint = "sum()", CharSet = CharSet.Unicode)]

public static extern int sum(wchar_t* param);

1>test.dll是載入的dll

2>sum()是dll中的函數

3>param是函數中的參數。

2.把wchar_t* 轉為stringbuilder/string

 [DllImport("test.dll", EntryPoint = "sum()", CharSet = CharSet.Unicode)]

public static extern int sum(StringBuilder param);

調用時候:

sum("hello world !")

總結:設置charset 就可以用stringbuilder代替wchar_t*

 看到的另一種方法:

[DllImport("Netapi32.dll", EntryPoint = "NetUserChangePassword", CharSet = CharSet.Unicode)]
public static extern int NetUserChangePassword(
[MarshalAs(UnmanagedType.LPWStr)] string domainname,
[MarshalAs(UnmanagedType.LPWStr)] string username,
[MarshalAs(UnmanagedType.LPWStr)] string oldpassword,
[MarshalAs(UnmanagedType.LPWStr)] string newpassword);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM