CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 1999
    Posts
    1

    LIB File Loading...

    I am about to create a DLL that needs to run on all Windows OS versions (95/98/NT/W2K) and only need to link a library file and load it's associated DLL when a specific printer driver has been loaded.

    Any suggestions on how to avoid any potential pitfalls and idea's about how to make this as slick as possible would be greatly appreciated.

    Thanks!

    - Chris

  2. #2
    Guest

    Re: LIB File Loading...

    To use a DLL dynamically, you need to be aware of function pointers. I still find the definitions tricky... When the DLL is loaded, then you can get the function pointers by telling the function names. If you are unshure about the names, you can use the quick view feature of the Windows Explorer (right-click on a DLL).


    HINSTANCE hMyLib;
    MYFUNCTIONTYPE fnMyFunction;

    hMyLib = LoadLibrary("mystuff.dll"); // load the library
    if (hMyLib == NULL) // not found
    return FALSE;

    fnMyFunction = (MYFUNCTIONTYPE) GetProcAddress(hMyLib, "MyFunction");
    if (fnMyFunction==NULL)
    return FALSE;
    // get more function pointers here...



    // now you can call the function
    int nTest = fnMyFunction(0, 0, 0); // just an example



    // ... your follow-up code


    if (hMyLib != NULL)
    FreeLibrary(hMyLib); // release the library, unload the dll






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

Featured