Christian Smith
<[EMAIL PROTECTED]> wrote:
This is one of the most painful aspects of Windows programming (among
many) but can be somewhat mitigated by doing away with .def files:
http://msdn2.microsoft.com/en-us/library/3y1sfaz2.aspx
Basically, wrap the above in a macro, something like:
#ifdef WIN32
#define EXPORT __declspec( dllexport )
#else
#define EXPORT
#endif
This technique still doesn't allow a DLL to link back to a symbol
exported from an EXE, without jumping through hoops - the original topic
of this thread.
Another problem is that __declspec(dllexport) does not allow one to
export an unmangled undecorated name exactly as it appears in your
source code: at best you get an extra underscore in front, at worst you
get a C++ mangled name. To export an undecorated name one still has to
use .def files. And people using the DLL via LoadLibrary /
GetProcAddress are rarely amused when the name they have to use in
GetProcAddress does not match that in the documentation and header
files.
You may have to dllimport the required function from the .exe to the
dll. I don't know for sure.
The way it works, the linker produces a so-called import library (.LIB)
together with the DLL. Import library has the same structure as a
regular static library, but instead of actual code it contains
references to its companion DLL. When building the EXE, you simply link
against this import library as you would against a static library.
Note an inherent chicken and egg problem: you can't build two DLLs (or
an EXE and a DLL) using this approach where a circular dependency
exists, that is, where DLL A needs a function exported from DLL B, and
at the same time DLL B needs a function exported from DLL A. To
successfully link DLL A, you need an import library from DLL B, but an
import library is produced as a side effect of link process, and to link
DLL B you need an import library from DLL A, which you can't build until
you've built B, ... There is a way to break this circle with the use
of so called export files (.exp ), but the technique is rather
cumbersome. You don't want to go that way unless there's a gun to your
head.
Igor Tandetnik