DllImport with CallingConvention.StdCall and _cdecl

  • Thread starter Thread starter Ezmeralda
  • Start date Start date
E

Ezmeralda

Hello,

in some old projects I am using DllImport with its default
CallingConvention.StdCall, but the according DLL uses
standard _cdecl calling convention.
To my understanding this should not work, since the
calling convention does not agree - in fact it seems to
work since we did not notice any problems.

Could someone explain what's going on?

Thanks!
 
Ezmeralda said:
Hello,

in some old projects I am using DllImport with its default
CallingConvention.StdCall, but the according DLL uses
standard _cdecl calling convention.
To my understanding this should not work, since the
calling convention does not agree - in fact it seems to
work since we did not notice any problems.

Could someone explain what's going on?

Thanks!

The interop layer is able (to a certain extend) to correct calling convention mismatches,
however you better change your code so the caller matches the callee, else you'll incur a
small performance hit. Note that this hack is only for correcting managed to unmanaged
calls, not for unmanaged callbacks.

Willy.
 
Back
Top