Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Threading DLLs

Status
Not open for further replies.

ithic

Programmer
Sep 18, 2002
23
0
0
US
I'm trying to use ActiveWire and it's usb dll, but I'm having a little trouble.

In the documentation it says...

"If your application needs to open 2 or more devices, create threads, load DLL in each thread, then open device with different devnum."

However, in Windows when I use CreateThread (included in windows.h) to create a thread with the LoadLibrary function in it, the new thread does not create an unique handle. Eg. when opening a second device, it would only allow me to access that second device in BOTH threads.

I'm not sure if this is relevant, but in hunting for the problem I can safely say that LoadLibrary in both threads returns the same exact handle instance (id).

I've also found that when I start a second process loading the same DLL, it will in fact allow me to access two different devices at the same time. However, I'd like it to have access to different devices in differents threads but in the same process.

I have found an alternate solutions to my problem, however it's a dirty fix and would like to do otherwise:

Create copies of the dll: Eg. copy awusb.dll to another file like awusb0.dll and awusb1.dll and call LoadLibrary( "awusb0.dll" ) for one thread, and "awusb1.dll" for the other.

Does anyone have any ideas? Any help would be appreciated.
 
>> Does anyone have any ideas?

That is the only way I know how to accomplish that. With the exception that you can limit your need to a single file if you give the filename a long name. That way you can call LoadLibrary once with the long name of the file and then the second time using the short name. At least that used to work several years ago.


-pete
 
The LoadLibrary function maps the DLL into the process address space therefore I would expect the handle returned by the function to be consistent across all threads of the process. This is because the DLL is only loaded once into the process address space until it is unloaded, vai FreeLibrary.

I would assume that you intend to call some functions contained within this DLL at some stage in your code by obtaining the address of the function using GetProcAddress. There should be no problem with using a constistent handle as one of the arguments to this function in the different threads of your process.

Are you aware that it is sometimes recommended to use the beginthread function (and subsequent endthread function to terminate the thread) instead of CreateThread function to create a new thread that uses functions from the C run-time library?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top