Sign in to follow this  
phraine

DLL Problem

Recommended Posts

phraine    144
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... :)

Share this post


Link to post
Share on other sites
Evil Steve    2017
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.

Share this post


Link to post
Share on other sites
phraine    144
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?

Share this post


Link to post
Share on other sites
Evil Steve    2017
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this