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

后端 未结 2 1889
予麋鹿
予麋鹿 2021-01-18 18:06

A C# WPF application I am working on contains many calls to an unmanaged external DLL. All calls to the DLL work as expected when running the application normally (i.e. outs

相关标签:
2条回答
  • 2021-01-18 18:44

    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.

    0 讨论(0)
  • 2021-01-18 18:57

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

    0 讨论(0)
提交回复
热议问题