Any idea what can cause “vshost32.exe has stopped working” in Visual Studio 2013?

我与影子孤独终老i 提交于 2019-12-01 18:10:26

The vshost32.exe error is caused by an incorrect DllImport statement - the return type of the external DLL cannot be string, it must be IntPtr.

Here is the corrected code:

[DllImport("Client.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr ClientGetVersion();

...and this is the revised call to the DLL method:

string version;

try
{
  version = Marshal.PtrToStringAnsi(ClientGetVersion());

}
catch (Exception ex)
{
  // Error handling omitted for clarity...
}

Thanks to @HansPassant for the answer.

Quit Visual Studio and Relaunch in Administrator Mode. It Work!!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!