Failing to GetProcAddress

504 Views Asked by At

I'm having trouble with loading a DLL in my assignment project.

Here's the header file:

I have omitted code that works and is irrelevant to the problem. Basically, hinstLib is not NULL but when the line Filter = (FILTPTR) GetProcAddress(hinstLib, "Filter"); is executed, Filter has no value. To me it seems like it is saying that the DLL has been found but it cannot find the function "Filter" inside the DLL and I have no idea why, albeit I could be wrong. I still haven't got my head around how some of this works.

Here is the DLL:

Any ideas anyone? All help is greatly appreciated!

  • James
2

There are 2 best solutions below

3
Swift - Friday Pie On

Your specifiers are wrong. A good, concise way do to this is to use same header to in DLL and APP, defining the export-import interface., which uses macro like this:

#ifdef MY_DLL_EXPORTS
#define MY_DLL_API __declspec(dllexport)
#else
#define MY_DLL_API __declspec(dllimport)
#endif

And declarations:

extern "C" MY_DLL_API int Filter(int* data, int count, const WCHAR* parameterString);

Library's .cpp file would use this header and would define MY_DLL_EXPORTS.

If I understand your code right, you made it so that linker tries to export same function from both modules? ALso, function's prototype should be C-compatible to be actually extern "C"

0
Remy Lebeau On

when the line Filter = (FILTPTR) GetProcAddress(hinstLib, "Filter"); is executed, Filter has no value. To me it seems like it is saying that the DLL has been found but it cannot find the function "Filter" inside the DLL and I have no idea why

The function is likely being exported with a decorated name. You are not specifying a calling convention, so the default is usually __cdecl, which prefixes the function name with an underscore, thus it would be exported as "_Filter" instead. But this is compiler-specific behavior, so double-check your DLL's EXPORTS table with a PE viewer/dumper to see the actual name being exported. You may need to add a .def file to your project to ensure the function is exported as "Filter" as desired.