Re: Exporting function in VS2008 DLL

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Leon" wrote:
This is a brief description of my sample project. I have a Foo.h
which contains this:
//Foo.h
#ifdef BUILD_MYDLL
#define DLLENTRY __declspec(dllexport)
#else
#define DLLENTRY __declspec(dllimport)
#endif

extern "C" { DLLENTRY int Foo(LPCTSTR); }

In addition to other replies. Do not forget to put the calling
convention for an exported function, for example:

extern "C" { DLLENTRY int __stdcall Foo(LPCTSTR); }

Calling convention mismatch between DLL and a client is one of the
most common mistakes. By specifying calling convention explicitly
you ensure that this error won't happen.

HTH
Alex


.



Relevant Pages

  • DLL import
    ... DllEntry proc hInstDLL:DWORD, reason:DWORD, reserved1:DWORD ... DllEntry Endp ... Addxy proc A:DWORD, B:DWORD ... different calling convention." ...
    (comp.lang.asm.x86)
  • Re: DLL import
    ... Regardless which calling convention is used, ... | DllEntry proc hInstDLL:DWORD, reason:DWORD, reserved1:DWORD ... | Addxy proc A:DWORD, B:DWORD ...
    (comp.lang.asm.x86)
  • Re: Exporting function in VS2008 DLL
    ... #define DLLENTRY __declspec ... extern "C" {DLLENTRY int Foo;} ... unless I include the dllexport in the function definition as follows: ... I would always repeat the 'extern "C"' ...
    (microsoft.public.vc.language)
  • Re: Exporting function in VS2008 DLL
    ... #define DLLENTRY __declspec ... extern "C" {DLLENTRY int Foo;} ... Then the definition of Foo() is defined in Foo.cpp as follows: ...
    (microsoft.public.vc.language)