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
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!!!