|
Archives
D Programming
digitalmars.Ddigitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger D.gnu D C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
c++.windows.32-bits - Can't link explicitly with a DLL
I'm trying to build a DLL with DMC++ to explicitly link with at runtime. My
intent is to make use of a global factory function.
I get no error messages while building, but at runtime GetProcAddress() fails.
I believe the symbol name may be mangled but I thought declaring the function
with extern "C" and __stdcall would unmangle it for me.
First, here are the files (stripped to bare minimum to demonstrate the problem):
[Foo.h]====================================================================
#ifndef FOO
#define FOO
#ifdef BUILD_DLL
#define FOOAPI __declspec(dllexport)
#else
#define FOOAPI __declspec(dllimport)
#endif
struct FOOAPI Foo
{
Foo();
virtual ~Foo();
};
#endif
[Foo.cpp]==================================================================
#include "Foo.h"
Foo::Foo()
{ }
Foo::~Foo()
{ }
BOOL WINAPI DllMain (HINSTANCE, DWORD, LPVOID)
{
return TRUE;
}
extern "C" __declspec(dllexport) Foo* __stdcall create()
{
return new Foo;
}
[TestDll.cpp]==============================================================
#include "Foo.h"
#include <windows.h>
#include <iostream>
using namespace std;
typedef Foo* (__stdcall *CreateFunc)();
int main()
{
HMODULE dll (LoadLibrary ("Foo.dll"));
if (!dll) {
cerr << "LoadLibrary: Failed!" << endl;
return 1;
}
CreateFunc create (
reinterpret_cast<CreateFunc>(GetProcAddress (dll, "create")));
if (!create) {
cerr << "GetProcAddress: Failed!" << endl;
return 1;
}
FreeLibrary (dll);
return 0;
}
I can't get past the call to GetProcAddress(). LoadLibrary() returns
successfully so I am finding the DLL at runtime and loading it.
Here is my build procedure from the command line:
dmc -ND -I\dm\stlport\stlport -DBUILD_DLL -c Foo.cpp
dmc -WD -oFoo.dll Foo.obj kernel32.lib
dmc -ND -I\dm\stlport\stlport -c TestDll.cpp
dmc -otestdll.exe TestDll.obj
I run the test and get:
GetProcAddress: Failed!
What am I doing wrong? I want to avoid putting aliases for symbols in a .def
file. Note above that I'm not using a .def file but I'm explicitly importing and
exporting the symbols.
Is there a way to see the symbols in a DLL with the tools from the DMC++
package?
Thanks! I'd appreciate any help with this. It's driving me nuts! :-(
/Michael
Mar 25 2004
"Michael" <Michael_member pathlink.com> wrote in message news:c40c4e$hmf$1 digitaldaemon.com...Is there a way to see the symbols in a DLL with the tools from the DMC++ package? Mar 26 2004
I get no error messages while building, but at runtime GetProcAddress() fails. I believe the symbol name may be mangled but I thought declaring the function with extern "C" and __stdcall would unmangle it for me. Mar 26 2004
|