#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    42
    Rep Power
    11

    using multiple dlls


    i need to use multiple dlls, they dont have to intercommunicate. any body know how to get my executable to use them?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    42
    Rep Power
    11
    Doesnt anybody know this?:confused:
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,593
    Rep Power
    4207
    What development environment are you using? Visual C++ or Borland C++. Also, are these Active-X DLLs or plain old DLLs?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    42
    Rep Power
    11
    sorry i wasnt clearer before, im using Dev-C++ and just plain old dlls will do fine.:)
  8. #5
  9. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    implicit (at run, easiest but whole app will fail if DLL not found) or explicit (as needed) linking?

    Look at LoadLibrary(), GetProcAddress()

    here is a quick example to explicitly load the function TrackMouseEvent() from the user32.dll

    Code:
    //define a funtion type
    typedef BOOL (CALLBACK * TEST)(LPTRACKMOUSEEVENT);
    //declare an instance of this function type
    TEST				Test_TrackMouseEvent;
    //DLL handle
    HANDLE   hTME=NULL:
    
    //ensue we are where the DLL will be found
    SetCurrentDirectory(szDLLInThisDirectory);
    //load up the DLL
    hTME=LoadLibrary(".\\user32.dll");
    if (hTME!=NULL)
    {
    //get the function we want and lock to our function pointer	
    Test_TrackMouseEvent=(TEST)GetProcAddress(hTME,"TrackMouseEvent");
    
    //error check
    if(Test_TrackMouseEvent==NULL)
    {
    	iError=GetLastError();
    }
    //use if no error
    
    
    //free library after use
    FreeLibrary(hTME);
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    42
    Rep Power
    11

    Smile


    wow, thanks so much! :)
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    42
    Rep Power
    11
    Well i tried this now and i had a few problems. I fixed a typo and got rid of iError. Now ANSI C++ is causing me some problems. I get two Errors:

    ANSI C++ forbids implicit conversion from `void *' in argument passing


    ANSI C++ forbids implicit conversion from `void *' in argument passing

    One points to this:


    Code:
    hTME=LoadLibrary(".\\user32.dll");
    and this:



    Code:
    FreeLibrary(hTME);
    Does anybody have any idea of how to fix this? remember i am using Dev-C++.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    42
    Rep Power
    11
    Doesn't anybody know how to make this ANSI compliant???:(
  16. #9
  17. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    well i've never used Dev-C++ but if i got that error i would try casting those arguments to (void *).
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    42
    Rep Power
    11
    i found out what the problem was:
    it doesnt like HANDLE hTME=NULL;

    i got rid of hTME and only check if it loads the function (close enough) but now it doesnt load the dll. oh, i also got rid of SetCurrentDirectory(szDLLInThisDirectory);
    szDLLInThisDirectory was undefined, i didnt feel like defining it and i dont think it really needs it.

    Is there something i need to do different in the dll to make it load that function?
  20. #11
  21. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    The dangers of using code you do not understand.............Each line has a specific and at times essential purpose.

    SetCurrentDirectory(szDLLInThisDirectory);

    Ensures you are in the folder the DLL is in. I use GetCurrentDirectory() to 'fill in' szDLLInThisFolder as the app starts and keep as a global. I included it to show you that you must set the full path or set the app to look in the folder containing the DLL.

    hTME=LoadLibrary(".\\user32.dll");

    This actually loads the DLL. Without it you can't lock the functions down with GetProcAddress()

    I seem to have led you astray. hTME should have been a HMODULE not a HANDLE (but HANDLE will work).

    If you still get the error try a cast back to the type you want ie HMODULE
    HINSTANCE will also work as HMODULE is a #define of HINSTANCE.

    hTME = (HMODULE)LoadLibrary( ".\\user32.dll" );

    or

    hTME = (HANDLE)LoadLibrary( ".\\user32.dll" );

    FreeLibrary(hTME);

    is also essential as it frees the memory and resoucres associated with the DLL.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa

IMN logo majestic logo threadwatch logo seochat tools logo