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

## Recommended Posts

I am trying to use a runtime DLL but after I have called LoadLibrary (which is successful) GetProcAddress is returning NULL. I know the DLL is correct as I got it working by including it at load time (inluding the header and lib as well as the dll) in another project. This is the header file for the DLL:
#define DLLDIR _declspec(dllexport)

void DLLDIR DLLfun1(char*);
int DLLDIR DLLfun2(int);

extern int DLLDIR DLLArg;

class DLLDIR DLLclass
{
public:
DLLclass();
~DLLclass();
int Sub(int, int);
int Arg;
};
And this is the source file where I call GetProcAddress:
#include <iostream>
#include <windows.h>
using namespace std;

typedef void (*FUNC1)(char*);
typedef int (*FUNC2)(int);

int main()
{
FUNC1 pfun1;
FUNC2 pfun2;
HMODULE hMod;

DWORD dRes = GetLastError();

(pfun1)("Hello World\n");
int a = (pfun2)(30);

cout << a;

bool bRes = FreeLibrary( hMod );

system("Pause");
}
I called GetLastError and it returned 127 which is: The specified procedure could not be found. ERROR_PROC_NOT_FOUND I don't understand why it can't find the function in the DLL! Especially since I have, like I mentioned, used the functions when loading the DLL at load time. Any help will be great thanks

##### Share on other sites
You're probably experiencing name mangling issues. Try declaring the functions as extern "C" or using .DEF file for the DLL exports.

##### Share on other sites
So from looking at it the code looks ok? What do you mean by using .DEF file for the DLL exports?

##### Share on other sites
SICrane you are a hero, i messed about with this for 4 hours the other day, adding extern C did work...I've seen it a few times while I've been researching but I didn't think I'd need it.

Thanks again

• 38
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631365
• Total Posts
2999583
×