|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
Doesnt anybody know this?
![]() |
|
#3
|
||||
|
||||
|
What development environment are you using? Visual C++ or Borland C++. Also, are these Active-X DLLs or plain old DLLs?
|
|
#4
|
|||
|
|||
|
sorry i wasnt clearer before, im using Dev-C++ and just plain old dlls will do fine.
![]() |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
|||
|
|||
|
wow, thanks so much!
![]() |
|
#7
|
|||
|
|||
|
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++. |
|
#8
|
|||
|
|||
|
Doesn't anybody know how to make this ANSI compliant???
![]() |
|
#9
|
||||
|
||||
|
well i've never used Dev-C++ but if i got that error i would try casting those arguments to (void *).
|
|
#10
|
|||
|
|||
|
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? |
|
#11
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > using multiple dlls |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|