[UnmanagedFunctionPointer(CallingConvention.Cdecl)]

In .NET when calling Unmanaged Code from Manged Code using Delegates,Callback functions are implemented in .NET using delegates, and all delegates use the StdCall calling convention.

Use " [UnmanagedFunctionPointer(CallingConvention.Cdecl)]" attribute while declaring the delegate if your unmanaged Win32 API is declared with Cdecl calling convention.

Ref:

http://www.informit.com/guides/content.aspx?g=dotnet&seqNum=473

http://social.msdn.microsoft.com/Forums/en-US/clr/thread/8f62e785-691e-4fe8-87fb-1f60657c80aa