Issue with dynamically loaded DLL and null function pointers

Started by
3 comments, last by mikfig 14 years, 1 month ago
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.
Advertisement
ignore, misread
What's the definition of "string"? Does it fail if you use LPWSTR instead of string?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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
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();
"WARNING: Excessive exposure to politicians and other bureaucrats has been linked to aggressive behavior." - Henk Hopla

This topic is closed to new replies.

Advertisement