首页 > 代码库 > C# 调用 c++ 非托管dll时wchar类型参数的乱码处理

C# 调用 c++ 非托管dll时wchar类型参数的乱码处理

1         [DllImport("user32.dll", CallingConvention = CallingConvention.WinApi)]
2         public static extern IntPtr FindWindow(
3             [MarshalAsAttribute(UnmanagedType.LPWStr)] string lpWindowClass,
4             [MarshalAsAttribute(UnmanagedType.LPWStr)] string lpWindowName
5         );

在相应的参数前加上 [MarshalAsAttribute(UnmanagedType.LPWStr)] ,这样就不会导致乱码了

C# 调用 c++ 非托管dll时wchar类型参数的乱码处理