Search code examples
c#c++visual-studio-2008dllexportcalling-convention

What is the default calling convention for exported functions (VS2008)?


Given the following C++ code which doesn't mention a calling convention in the function declaration, what will the calling convention be for the exported function Exported? My guess would be a default of cdecl.

extern "C"
{
  __declspec (dllexport) bool Exported(int parm);
}

I'm calling this function from managed code, using LoadLibrary, GetProcAddress, and Marshal.GetDelegateForFunctionPointer. I can decorate my delegate definition with different values of the UnmanagedFunctionPointer attribute and they all seem to work.


Solution

  • The default calling convention is cdecl. Note that __declspec(dllexport) has no influence on calling convention.

    The calling convention can be specified in code, or by a compiler option. I don't recommend using the compiler option, it's a bit too obscure. Make it explicit in code and then anyone reading if knows what convention is used.

    Note that for 64 bit Windows code, all calling conventions are equivalent which could explain what you see.