当一切都是char时,我这样做:
class call_dll
{
[DllImport("my.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int myfunc(string aTitle, string aMessage);
}
但是如果aTitle是wchar和aMessage char?我该怎么办?
答案 0 :(得分:3)
您可以像这样使用MarshalAsAttribute
:
class call_dll
{
[DllImport("my.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int myfunc(
[MarshalAs(UnmanagedType.LPWStr)] string aTitle,
[MarshalAs(UnmanagedType.LPStr)] string aMessage);
}
请参阅docs for the UnmanagedType
enum以供参考。