Jump to content
  • Advertisement
Sign in to follow this  
ambershee

Issue with dynamically loaded DLL and null function pointers

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

Hi guys, I'm going absolutely mad trying to get my function pointers to work correctly - I can load the DLL, but the function pointers always return an unused value no matter what I do with them, or how I rewrite them. You're looking at many, many hours of frustration, reading, debugging, experimenting and generally getting nowhere. Here's a version with the unecessary gubbins thrown out; Usage (directory and functionName are appropriate and correct strings)
	HINSTANCE hinstLib;
	hinstLib = LoadLibrary(directory);

	DWORD error = GetLastError();

	typedef string(*GetString)();

	GetString getString = (GetString)GetProcAddress(hinstLib, functionName);
DLL Header
#ifndef ASEXPORT
#define DLLIMPORTOREXPORT dllimport
#else
#define DLLIMPORTOREXPORT dllexport
#endif

extern "C"__declspec(dllexport) string GetString();
Not that GetLastError returns 0 (completed successfully). Any ideas on what I should be looking at? I've tried writing this in quite a few different ways, so there must be something fundamentally wrong somewhere.

Share this post


Link to post
Share on other sites
Advertisement
Edit: Clarification.

I just used non-specific string types for the purposes of example.

The real strings in the application are std::string, but have been converted using c_str() when used in the windows function calls. For the record, I'm using the multi-byte character set.

Thanks,

Luke

Share this post


Link to post
Share on other sites
Are you using that dll header for both the importing and exporting of the functions? Because when you forward declared the GetString function in the dll header you wrote it as:
extern "C"__declspec(dllexport) string GetString();

instead of using the macro that differs on if you are importing or exporting, i.e. like this:

extern "C"__declspec(DLLIMPORTOREXPORT) string GetString();

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!