07-31-2005 02:08 PM
08-01-2005 10:27 AM
08-01-2005 10:52 PM
John,
Sorry for the lack of details. First of all, we're using LabWindows/CVI. We have written a dll that performs an 'executive' type of function. This 'main' dll loads three other 'sub' dlls. One of the sub dlls contains calls to a power supply ivi driver. What we have observed is that when the application executes it loads all the 'sub' dlls first before the 'main' dll loads. So we could track which dlls load first we put a MessagePopup() in each of the dlls' DllMain() functions shown below.
int __stdcall DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
if (InitCVIRTE (hinstDLL, 0, 0) == 0)
return 0; /* out of memory */
MessagePopup ("Message", "Main Dll loading...");
break;
case DLL_PROCESS_DETACH:
CloseCVIRTE ();
break;
}
return 1;
}
We are attempting to do an initialization of all instruments when the 'main' dll loads. Since is seems that the sub-dlls get loaded before the main-dll does, we expected to be able to do this. Usually we get a error message if the application makes a function call to a dll that has not yet been loaded. We get no errors in this case. When we get to the ivi function call hp6610xx_init() within one of the sub-dlls it never returns.
Regards,
Dan
contains some calls to a ps ivi driver. When this
08-02-2005 10:24 AM
Dan,
This is from MSDN documentation for DllMain:
=================
In general, your DLL entry-point function should perform only simple initialization tasks, such as the following:
Do not call LoadLibrary in the entry-point function, because you might create dependency loops in the DLL load order. This can cause a DLL to be used before the system executes its initialization code.
Similarly, do not call the FreeLibrary function in the entry-point function on detach, because this can cause a DLL to be used after the system executes its termination code.
Calling Microsoft® Win32® functions other than TLS, object-creation, and file functions can cause problems that are difficult to diagnose.
==========================
Since the IVI driver init() function initializes the COM library and the IVI Confioguration COM API, it is a bad idea to call init() in the DllMain() function. You are likely to run into problems at application load and unload time because the order of load/unload of dependent libraries is not guaranteed. Therefore, I recommend that you perform initialization outside of your DllMain(). One idea would be to create an explicit initialization routine in your DLL that is explicitly called by the client after all DLLs have loaded.
Best Regards,
ZHaider