Jump to content

Recommended Posts

Posted

Actual Microsoft example

// File:  RUNTIME.C
// A simple program that uses LoadLibrary and 
// GetProcAddress to access myPuts from MYPUTS.DLL. 

#include <stdio.h> 
#include <windows.h> 

typedef VOID (*MYPROC)(LPTSTR); 

VOID main(VOID) 
{ 
    HINSTANCE hinstLib; 
    MYPROC ProcAdd; 
    BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; 

    // Get a handle to the DLL module.

    hinstLib = LoadLibrary("myputs"); 

    // If the handle is valid, try to get the function address.

    if (hinstLib != NULL) 
    { 
        ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts"); 

        // If the function address is valid, call the function.

        if (fRunTimeLinkSuccess = (ProcAdd != NULL)) 
            (ProcAdd) ("message via DLL function\n"); 

        // Free the DLL module.

        fFreeResult = FreeLibrary(hinstLib); 
    } 

    // If unable to call the DLL function, use an alternative.

    if (! fRunTimeLinkSuccess) 
        printf("message via alternative method\n"); 
}
  • 1 month later...
Posted

I am very interested in this as I have been learning C++ for a couple of weeks now. Using the code above, how could you dynamically load a function from a dll, with or without parameters, like AutoIt does?

Posted

A couple weeks? In 6 - 12 months, come back to Windows programming in general. Another 2-3 months after that take a look at DLLs. Crawling before you walk, walking before you run and all that.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...