Sign in to follow this  

Issue with dynamically loaded DLL and null function pointers

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
#define DLLIMPORTOREXPORT dllexport

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
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.



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

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