时,我有一个Windows窗体应用程序在.NET 4.0下运行。此应用程序导入一个DLL,其可用于:应用程序崩溃使用字符串函数
- 32位
- 64位
这里是我的代码片段:
[DllImport("my64Bit.dll"), EntryPoint="GetLastErrorText"]
private static extern string GetLastErrorText();
// Do some stuff...
string message = GetLastErrorText();
当调用这个函数(编译为64位)应用程序崩溃。我什至不能在Visual Studio 2012中看到任何调试消息。与32位-DLL(编译为x86)相同的代码工作正常。原型为:
LPCSTR APIENTRY GetLastErrorText()
不幸的是我没有对DLL任何进一步的信息,因为它是一个第三方产品。
http://stackoverflow.com/questions/3598226/how-to-map-win32-types-to-c-sharp-types-when-using-p-invoke – NickD
LPCSTR是char *。尝试将CharSet = CharSet.Ansi添加到DllImport。 –
@AlexFarber据我所知,默认的CharSet是Ansi。无论如何,该应用程序仍然崩溃。如前所述,32位版本运行良好。 –