i have a function defined as:
I want to be able to load this up and run it but so i can load this function from different dlls (specified at run time).Code:int functionCall (int index) { return index * 2; }
I have used LoadLibrary, GetProcAddress etc to get all the details, the only problem is when wanting to call it.
Msdn uses:
to which i changed to:Code:typedef UINT (CALLBACK* LPFNDLLFUNC1)(UINT, DWORD);
although when it comes to running my program this generates an error. my full code is:Code:typedef int (CALLBACK* LPFUNCTION)(int);
Code:#include <iostream.h> #include <windows.h> typedef int (CALLBACK* LPFUNCTION)(int); HINSTANCE dllHandle; LPFUNCTION dllFunction; int main (void) { dllHandle = LoadLibrary("1.dll"); if (dllHandle != NULL) { dllFunction = (LPFUNCTION)GetProcAddress(dllHandle, "functionCall"); if (!dllFunction) { FreeLibrary(dllHandle); return -1; } else { cout << "DLL Function Loaded:" << dllFunction << endl; int uReturnVal = dllFunction(100); cout << "Return:" << uReturnVal << endl; } } return 0; }


Reply With Quote
