PInvoke Unbalances the stack

Posted by Giawa on Stack Overflow See other posts from Stack Overflow or by Giawa
Published on 2010-04-24T23:29:51Z Indexed on 2010/04/24 23:33 UTC
Read the original article Hit count: 614

Filed under:
|
|
|

Good afternoon,

I have been working on a dll that can use CORBA to communicate to an application that is network aware. The code works fine if I run it as a C++ console application. However, I have gotten stuck on exporting the methods as a dll. The methods seems to export fine, and if I call a method with no parameters then it works as expected. I'm hung up on passing a C# string to a C++ method.

My C++ method header looks like this: bool __declspec(dllexport) SpiceStart(char* installPath)

My C# DLL import code is as follows: [DllImportAttribute("SchemSipc.dll", CharSet=CharSet.Ansi)] private static extern bool SpiceStart(string installPath);

I call the method like so: bool success = SpiceStart(@"c:\sedatools");

The call to SpiceStart throws the exception "PInvokeStackImbalance", which "is likely because the managed PInvoke signature does not match the unmanaged target signature."

Does anyone have any suggestions? If I remove the char* and string from the parameters, then the method runs just fine. However, I'd like to be able to pass the installation path of the application to the dll from C#.

Thanks in advance,

Giawa

© Stack Overflow or respective owner

Related posts about c#

Related posts about pinvoke