LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to know if parent application is still running(active) from dll?

I have written a dll in which I have multiple threads. Threads run forever until uninitialize function is called.  I am calling this dll from other CVI application which I am debugging. Sometimes my application exits prematurely(I am still working on it

 

CVI applications---->calls dll--->dll loads threads--->threads active in dll---> CVI application exits without uninitializing DLL

 

Is there anyway to know from dll if parent application is still running? I can terminate dll itself from dll if parent application is not active anymore.

 

Any other idea?

 

Thanks.

Message Edited by test_man on 01-13-2010 05:22 PM
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 1 of 3
(3,545 Views)

You could work with the DLL_PROCESS_DETACH case within the DllMain() function - I think this should still be called by the system even in the event of a calling process crash. Worth a try.

 

JR

Message 2 of 3
(3,528 Views)

DllMain will be called if the process is terminating, but MSDN give a pretty strong warning about doing anything under these circumstances:

 

When handling DLL_PROCESS_DETACH, a DLL should free resources such as heap memory only if the DLL is being unloaded dynamically (the lpReserved parameter is NULL). If the process is terminating (the lpvReserved parameter is non-NULL), all threads in the process except the current thread either have exited already or have been explicitly terminated by a call to the ExitProcess function, which might leave some process resources such as heaps in an inconsistent state. In this case, it is not safe for the DLL to clean up the resources. Instead, the DLL should allow the operating system to reclaim the memory. 

 

 While it's obvious from your question that you already know this, the best solution is to write your calling process in such a manner that you can guarantee the dll is uninitialized properly under all circumstances (assuming your code never crashes - a safe assumption right?? 🙂   )

 

NickB

National Instruments 

0 Kudos
Message 3 of 3
(3,514 Views)