• 9
• 16
• 15
• 12
• 9

# Issue with dynamically loaded DLL and null function pointers

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

## 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;

DWORD error = GetLastError();

typedef string(*GetString)();


#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 on other sites
What's the definition of "string"? Does it fail if you use LPWSTR instead of string?

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

Thanks,

Luke

##### 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();