Re: Module definition file problem
"Joachim" wrote:
Managed to solve the problem: In the hpp file I needed to
add
extern "C"
which them became
#ifdef EPAIP_EXPORTS
#define EPAIP_API extern "C" __declspec(dllexport)
#else
#define EPAIP_API extern "C" __declspec(dllimport)
#endif
What does this " extern "C"" mean and why do I need it?
The keyword `extern' modifies type of linkage for a variable
or function. When used with declaration of a variable,
`extern' causes it to have static duration. When used with
declaration of a functon, `extern' specifies external
linkage for the function (i.e., function name will be
visible from other translation units).
After keyword `extern' there is string literal, which
indicates target programming language. You need it if you
want to link with other modules written in that language.
Content of string literal is implementation defined, however
any decent C++ compiler supports at least two types: "C" and
"C++", because it's required by C++ Standard.
When you specify `extern "C"' linkage, then C++ compiler
stops name decoration (often called "name mangling") of
exported names. Without this modification your `initialize'
function name looks like this:
?initialize@@YGPAXXZ
which corresponds to undecorated declaration:
void * __stdcall initialize(void)
..
Usually, you use `extern "C"' modifier conditionally, like
this:
// epaip.hpp
#if defined(__cplusplus)
extern "C"
{
#endif
// declarations
EPAIP_API void* WINAPI initalize();
EPAIP_API HRESULT WINAPI terminate(void* a);
....
#if defined(__cplusplus)
}
#endif
So, modifier is visible only for C++ compilation.
I cannot seem to find any good reference on module
definition files which
not only describes what you can write in them but also
why you write the
different things in it.
Module definition files (.DEF) are discussed thoroughly in
MSDN:
"Module-Definition (.def) Files"
http://msdn2.microsoft.com/en-us/library/28d6s79h(vs.80).aspx
HTH
Alex