0

我可以使用out没有 StringBuilder 的具有字符串参数的 WinApi 函数吗?如果是,如何?或者这是从 WinApi 检索字符串的最简单方法?

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern uint FormatMessage(uint flags, IntPtr source, uint messageID, int languageID, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder buffer, int bufferSize, string[] arguments);

// I wished I could use it with just a string
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern uint FormatMessage(uint flags, IntPtr source, uint messageID, int languageID, ref [MarshalAs(UnmanagedType.LPWStr)] string buffer, int bufferSize, string[] arguments);

(我的功能可能有问题。我不确定)

4

0 回答 0