LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Launching a function from a DLL on first access

Hi All,

I would like to create a generic SW that can retrieve data from different DLL files. To do this I would like each of these DLL files to execute a single, pre-defined function when the SW accesses it for the first time (the SW will go over a directory with the DLL files to be used).

My problem is that I don’t want to change my SW each time I add a new DLL (declare the DLL function name to be executed on startup, etc.). I thought of using the DLL Attach mechanism but this will execute every time a function from the DLL will be called and not only once.
Do you know of any DLL properties that may help me do this?

Regards,

Gil
0 Kudos
Message 1 of 4
(3,345 Views)
The PROCESS_ATTACH in DllMain occurs the first time you load the dll into a process. So unless you are explicitly loading and unloading the dll in your SW everytime you call a function in the dll, you will get this event only once.

Or what you could do is always load a function with a specific signature and then make this a required condition for all dlls that your software uses. You basically recommend who ever is creating the dll to alwasy have a particular startup function defined. So kinda like agreeing on an interface for the dll to work with your app

Hope this helps
Bilal Durrani
NI
Message 2 of 4
(3,338 Views)
Hi Bilal,

I have managed to achieve my goal by loading the *.lib file(s) using LoadExternalModule and executing a unique entry point function in each DLL by using RunExternalModule.

Thank you very much for help,

Gil
0 Kudos
Message 3 of 4
(3,296 Views)
Thats great.

If you don't want to have to distribute the DLL and the import library with your CVI application, you might also consider using LoadLibrary() and GetProcAddress() ( part of the Windows SDK ) to load the DLL directly and call the function from it. Check out this KB here for more info.

Hope this helps
Bilal Durrani
NI
Message 4 of 4
(3,274 Views)