Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

ps ivi driver hangs when called during dll load

We are using a hp6610x ivi driver we downloaded from the NI website.  It seems to be working well with one exception.  We are experiencing a problem when we load our main dll and try to initialize our power supplies (using the ivi driver) during the dll loading event.  The application hangs.  We've traced the code down to the ivi init function call.  We've called the same init function after the dll loads and it works fine. 
 
Is there something that's missing during the main app's dll attach event that we should be aware of?  How can we troubleshoot this?  Any suggestions would be greatly appreciated.
 
Regards,
 
dq
0 Kudos
Message 1 of 4
(3,511 Views)
Hi Dan,

I am a bit confused about the order of events of your application.  As described in this Knowledge Base article, a dll is loaded in memory as soon as the VI calling that dll is loaded into memory.  As long as the VI is in memory, the dll also stays in memory.  How do you know that the dll is being loaded at the same time as the ivi init function?

Does the dll being loaded have anything to do with the instrument, or is it completely separate?  If the dll includes functions needed to communicate with the instrument, then it would be better to wait until the dll is completely loaded before initializing the power supplies.  Also, when the VI hangs while the dll is loading, does it pick back up and keep going once the dll is loaded?  Or do you have to restart the program to get it to work?

Have a great day!

john m
Applications Engineer
0 Kudos
Message 2 of 4
(3,505 Views)

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

0 Kudos
Message 3 of 4
(3,499 Views)

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:

  • Setting up thread local storage (TLS)
  • Creating synchronization objects
  • Opening files

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

Message 4 of 4
(3,484 Views)