NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

TestStand close notification from a DLL

How can I get a close notification from TestStand to my loaded DLL? I would like to have a message/notification from TestStand that it is in progress of shutdown, before it does FreeLibrary() on my DLL. This is to ensure that I always do a clean exit.
 
Alternatively; can I have TestStand call a function inside my DLL before doing FreeLibrary?
0 Kudos
Message 1 of 4
(3,378 Views)

You can use the dll entry point DLL_PROCESS_DETACH in your DLL which is executed each time teststand unloads your DLL. See also http://msdn2.microsoft.com/en-us/library/ms682583.aspx

In Teststand you can define when your DLL should be unloaded in the Step Properties of your C/C++ Prototype Adapter -> Run Options -> Unload Options. The Dll is also unloaded if Teststand shuts down.

If you use CVI you can insert the code needed with:

Edit->Insert Construct ->DLLMain

This is what you get:

 

#include <cvirte.h>

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 */
   break;

  case DLL_PROCESS_DETACH:

//here you can enter your clean up code: FreeLibrary(..)
   CloseCVIRTE ();
   break;
 }


 
 return 1;
}

 

0 Kudos
Message 2 of 4
(3,317 Views)
But when I receive the DLL_PROCESS_DETACH is after TestStand has unloaded the DLL file. Thus it does not give me any chance to properly  clean up.
0 Kudos
Message 3 of 4
(3,277 Views)

Ok, I see.

Do you know the TestStand API function TS_ExecutionInitTerminationMonitor and TS_GetTerminationMonitorStatus?

You can use these functions in your DLL to find out if a TestStand execution is terminating/terminated.

Hope this helps.

 

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