Jump to content
  • Advertisement
Sign in to follow this  
beebs1

DLL... Can someone explain?

This topic is 3892 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

Hiya, I've been experimenting with exporting functions from C++ in different ways, and I was wondering if someone could explain something. Consider this exported factory function:
namespace test {
   ITestInterface *CreateTestInterface();
}
When I export it using __declspec (dllexport), the function is exported as something like ?CreateTestInterface@test@@YGPAVITestInterface@12@XZ. However, when I use the following module definition file, the function is exported as just CreateTestInterface.
EXPORTS
CreateTestInterface @1
Both work, but the second is much easier to use with the Windows LoadLibrary() function. My question is how does the code using the library know that the function will return a test::ITestInterface, if the exported name does not reflect that using name 'mangling'? Is the name decoration just used when you link with a DLL, but not when you use it with the Load/FreeLibrary functions? I hope that was clear enough! Many thanks for any explanation [smile]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by beebs1
My question is how does the code using the library know that the function will return a test::ITestInterface, if the exported name does not reflect that using name 'mangling'?

It doesn't. LoadLibrary() just gets the address of the function and does not care about the parameters. No parameter information is stored at all (apart from the size of the parameters on the stack for stdcall calls).

Share this post


Link to post
Share on other sites
If you use LoadLibrary() and GetProcAddress() you need to cast the pointer to a function pointer type and pray that the type that you've cast it to matches the type that it actually is. There are no guarantees.

Share this post


Link to post
Share on other sites
Ah, I see. Thanks for the replies!

Would you say it's better to link implicitly with the library then, instead of using Load/FreeLibrary?

I've noticed that some large engines though, notably the new CryEngine 2, look like they use a module definition file. Can it not be used safely?

Thanks again.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!