Pinvoke unbalanced the Stack with dll


hi all,

i'm trying add .dll file (most written in c++) program , seems unmanaged code, have use dllimport function.

i have given function in .h file library i'd use. defined as

unsigned long ulgeneralaccess(const char*, char*, unsigned short);

i have changed unsigned long "ulong" , unsigned short "ushort".

so, dllimport looks like:

[dllimport("ver3.dll")]          public static extern ulong ulgeneralaccess(char[] uicommand, char[] acreturnbuffer, ushort buffer_length);

however, if call function, e.g. following code

string command = "init tool";              ulong reply = 0;              ushort buffer_length = 512;              char[] acrtbuffer = new char[5];              char[] accommandstring = new char[80];              char[] acreturnbuffer = new char[512];                  reply = ulgeneralaccess(accommandstring, acreturnbuffer, buffer_length);

i following error:

managed debugging assistant 'pinvokestackimbalance' has detected problem in '\my documents\visual studio 2010\projects\vrtt_reader\vrtt_reader\bin\debug\reader.vshost.exe'. additional information: call pinvoke function reader!reader.reader::ulgeneralaccess' has unbalanced stack. because managed pinvoke signature not match unmanaged target signature. check calling convention , parameters of pinvoke signature match target unmanaged signature.

i assume got data types somewhere wrong. can support me here? thanks.

another possibility is, dll calls dll...


info im http://social.msdn.microsoft.com/forums/en-us/user

hello again,

thanks input.  have performed measures "1)" , "3)" , function runs without error.  actually, using cdecl makes problem disappear.

regarding "2)", concerned: handing on in c++ pointers these strings not strings itself. actually, usage of function uigeneralaccess changed value of acreturnbuffer. how taken account?

benjamin


info im http://social.msdn.microsoft.com/forums/en-us/user

normally, you'd use stringbuilder (for portion native code write).  the marhsalling system handle this, provided pre-allocate stringbuilder's internal buffer appropriately.


reed copsey, jr. - http://reedcopsey.com
if post answers question, please click "mark answer" on post , "mark helpful".



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'