Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in .Net 4: PInvokeStackImbalance Exception

I was using the strlen function from msvcrt.dll in a .Net 3.5 project. More specifically:

private unsafe static extern int strlen( byte *pByte );

After migrating to .NET 4.0, if I use this function it throws a PInvokeStackImbalance exception.

How can I import the .NET 3.5 msvcrt.dll or fix this exception?

like image 764
SDReyes Avatar asked Dec 10 '22 16:12

SDReyes


1 Answers

I suspect that the problem is with the calling convention, you should be using Cdecl.

[DllImport("msvcrt.dll", CallingConvention=CallingConvention.Cdecl)]
private unsafe static extern int strlen(byte* pByte);
like image 104
Chris Taylor Avatar answered Dec 25 '22 11:12

Chris Taylor