Results 1 to 3 of 3

Thread: DLLS using loadlibrary

  1. #1

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    DLLS using loadlibrary

    If I use loadlibrary to load a dll, how would i import its functions

    i.e.

    dllname = pak.dll

    extern "C" void EXPORT SetValue ( float version )

    Is the name in the dll ?

    The full procedure run-down would be greatly appreciated

    thanks

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    Code:
    #include <windows.h>
    
    // typedef return_type(calling_convention *pfFunctioName)(arguments)
    typedef void(__cdecl *pfSetValue)(float);
    
    
    int main()
    {
    	// SetValue is a pointer to a function
    	pfSetValue SetValue; 
    
    	// Load the dll
    	HMODULE hPak = LoadLibrary("pak.dll");
    
    	// Check to make sure it worked...
    	if (!hPak)
    	{
    		MessageBox(NULL, "Failed to Load Library", "Error", MB_OK);
    		return 1;
    	}
    	// Find the address of the function
    	// (note that the name may be mangled if this is a c dll)
    	SetValue = GetProcAddress(hPak, "SetValue");
    
    	// Check to make sure it worked...
    	if (!SetValue)
    	{
    		MessageBox(NULL, "Failed to Find Address", "Error", MB_OK);
    		return 1;
    	}
    	
    	// call the function just like any other function.
    	SetValue(42.1);
    
    	return 0;
    }
    Last edited by sunburnt; Oct 14th, 2003 at 09:33 PM.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  3. #3

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    thanks heaps!

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