[Insight-users] PInvokeStackImbalance error when calling from VS2010 an ITK function defined in a dll.

sus_avi susana.garcia at oerc.ox.ac.uk
Thu May 19 11:08:54 EDT 2011


Hi,

I'm working with ITK 3.20 and VS2010 in x86 machine. I created a dll with
some itk funtions as follows:

____________

extern "C"
	{
__declspec(dllexport)  int BinaryThresholdImageFilter( char *
InputImageFile, char * OutputImageFile,  char * LowerThreshold, char *
UpperThreshold, char * OutsideValue, char * InsideValue)
}

______________

The call from VS 2010 C# is defined as follows: 

________________-

        [DllImport("itkFilters.dll", CallingConvention =
CallingConvention.StdCall)]
        public static extern int BinaryThresholdImageFilter(Byte[]
InputImageFile, Byte[] OutputImageFile, Byte[] LowerThreshold, Byte[]
UpperThreshold, Byte[] OutsideValue, Byte[] InsideValue);
        
  resultbinaryfilter = BinaryThresholdImageFilter(stbyteinputfilename,
stbyteoutputfilename, stbytelowerthreshold, stbyteupperthreshold,
stbyteoutsidevalue, stbyteindsidevalue);
               
______________

This works with no problem at all using VS2008. But when I run this on
VS2010 I get the following error: 

______________

PInvokeStackImbalance was detected
Message: A call to PInvoke function
'Test_ITKFilters!Test_ITKFilters.Program::BinaryThresholdImageFilter' has
unbalanced the stack. This is likely because the managed PInvoke signature
does not match the unmanaged target signature. Check that the calling
convention and parameters of the PInvoke signature match the target
unmanaged signature.
________________

I modified the code to see if the issue was about marshalling the data. I
created a very simple function within the same file with no arguments and
the code runs with no errors/warnings. But if I add a single parameter,
let's say (int x) and print it, it does print the value but it fails and
sends the same PInvoke error. 

Has anyone faced a similar issue? Suggestions are welcome and very much
appreciated. 

Thanks,

Susana 


--
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/PInvokeStackImbalance-error-when-calling-from-VS2010-an-ITK-function-defined-in-a-dll-tp6382376p6382376.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list