The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
using multiple dlls
Discuss using multiple dlls in the C Programming forum on Dev Shed. using multiple dlls C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 19th, 2003, 05:29 PM
|
|
Contributing User
|
|
Join Date: May 2003
Posts: 42
Time spent in forums: < 1 sec
Reputation 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?
|

May 19th, 2003, 08:53 PM
|
|
Contributing User
|
|
Join Date: May 2003
Posts: 42
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
Doesnt anybody know this? 
|

May 19th, 2003, 11:40 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
|
What development environment are you using? Visual C++ or Borland C++. Also, are these Active-X DLLs or plain old DLLs?
|

May 20th, 2003, 02:00 AM
|
|
Contributing User
|
|
Join Date: May 2003
Posts: 42
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
sorry i wasnt clearer before, im using Dev-C++ and just plain old dlls will do fine. 
|

May 20th, 2003, 04:54 AM
|
|
Offensive Member
|
|
Join Date: Oct 2002
Location: in the perfect world
|
|
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
|

May 20th, 2003, 01:06 PM
|
|
Contributing User
|
|
Join Date: May 2003
Posts: 42
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
wow, thanks so much! 
|

June 1st, 2003, 05:26 PM
|
|
Contributing User
|
|
Join Date: May 2003
Posts: 42
Time spent in forums: < 1 sec
Reputation 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:
Does anybody have any idea of how to fix this? remember i am using Dev-C++.
|

June 1st, 2003, 11:09 PM
|
|
Contributing User
|
|
Join Date: May 2003
Posts: 42
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
Doesn't anybody know how to make this ANSI compliant??? 
|

June 2nd, 2003, 11:47 AM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
|
well i've never used Dev-C++ but if i got that error i would try casting those arguments to (void *).
|

June 2nd, 2003, 06:28 PM
|
|
Contributing User
|
|
Join Date: May 2003
Posts: 42
Time spent in forums: < 1 sec
Reputation 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?
|

June 2nd, 2003, 09:15 PM
|
|
Offensive Member
|
|
Join Date: Oct 2002
Location: in the perfect world
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|