Results 1 to 2 of 2

Thread: LoadLibrary, GetProcAddress Etc

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341

    LoadLibrary, GetProcAddress Etc

    i have a function defined as:

    Code:
    int functionCall (int index) {
        return index * 2;
    }
    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).

    I have used LoadLibrary, GetProcAddress etc to get all the details, the only problem is when wanting to call it.
    Msdn uses:

    Code:
    typedef UINT (CALLBACK* LPFNDLLFUNC1)(UINT, DWORD);
    to which i changed to:

    Code:
    typedef int (CALLBACK* LPFUNCTION)(int);
    although when it comes to running my program this generates an error. my full code is:

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

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Whoop, Problem Solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width