Skip to main content
gamedev.net
🔒 Locked

DLL Problem

Started by phraine May 18, 2006 at 11:54 AM 2 replies 900+ views
Original Post
phraine
phraine
Can DLLs loaded during runtime (using LoadLibrary or dlopen interfaces) use functions defined in the executable which loaded them? I'm having a problem with a GUI DLL for my music sequencer, which cannot be linked due to unresolved references:
main.o(.text+0xe):main.cpp: undefined reference to `RegisterMainLoop'
I guess this is a dumb question, but I'm quite new at DLLs. On the other hand, Assembler, C, C++, Scheme and Haskell code snippets occur frequently in my dreams... :)
Evil Steve
Evil Steve
I'm not sure about on non-Win32, but on Win32, yes. You need to provide a prototype for the function so you don't get a compile error. If you make your exe export some symbols (with __declspec(dllexport)), then you'll get a .lib file generated, which you'll need to link with your DLL.

The other alternative is to export them as extern "C" __declspec(dllexport), and use GetProcAddress() (or dlsym() I think it is on Unix) to get the address of the function at runtime.

There's usually a cleaner way to do it though, such as calling a function in the DLL and passing it a function pointer (or a structure containing several function pointers) which the DLL can then use to call executable functions.
phraine
phraine
I knew it was something as simple as dllexport! Silly me...
Thanks.

Umm, one more dumb question...
Can member functions be __declspec(dllexport)ed just like regular ones?
Evil Steve
Evil Steve
Quote:
Original post by phraine
Can member functions be __declspec(dllexport)ed just like regular ones?
As far as I'm aware, you need to export an entire class. And you won't be able to use runtime linking to get the symbols (without a lot of hacking about), you'll have to link to the lib.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.