Jump to content
  • Advertisement
Sign in to follow this  

DLL Problem

This topic is 4386 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!