LabWindows/CVI

Content Type
Programming Language
Current manual

CVIRTEHasBeenDetached

CVIRTEHasBeenDetached

int CVIRTEHasBeenDetached (void);

Purpose

Indicates whether the operating system has detached the LabWindows/CVI Run-Time Engine from your executable process. The operating system detaches the run-time engine from a process in the following cases:

  • The process terminates.
  • The process dynamically unloads a DLL that uses the run-time engine, and the process does not directly link to the run-time engine.

You might need to use CVIRTEHasBeenDetached if you call LabWindows/CVI library functions in response to a PROCESS_DETACH message in the DllMain function of a DLL. In some cases, the operating system sends a PROCESS_DETACH message to the LabWindows/CVI Run-Time Engine before it sends a PROCESS_DETACH message to your DLL. When the LabWindows/CVI Run-Time Engine receives a PROCESS_DETACH message, it releases all the system resources it has acquired. When, in response to the PROCESS_DETACH message, your DLL calls LabWindows/CVI library functions that assume the system resources are still present, a general protection fault occurs.

A similar case occurs when you call the atexit function in a DLL to register a routine for the ANSI C library to execute when your DLL unloads. The ANSI C library calls your routine when the DLL receives a PROCESS_DETACH message. This can occur after the LabWindows/CVI Run-Time Engine receives a PROCESS_DETACH message. If your registered function calls LabWindows/CVI library functions that assume the system resources are still present, a general protection fault occurs.

To prevent such problems, call LabWindows/CVI functions from the PROCESS_DETACH code and registered functions in your DLL only if CVIRTEHasBeenDetached returns 0.

Example Code

int myPanel = 0;

int CreatePanel (void)
{

if ((myPanel = LoadPanel (0, "my.uir", MY_PANEL) < 0)

return 0;

atexit (CleanupPanels)
return 1;

}

static void CleanupPanels (void)
{

if ( ! CVIRTEHasBeenDetached())

if (panel > 0)

   DiscardPanel(myPanel);

}

Parameters

None.

Return Value

Name Type Description
runTimeEngineDetached int 1 = The run-time engine has already received the PROCESS_DETACH message. Do not call LabWindows/CVI library functions.

0 = The run-time engine has not yet received a PROCESS_DETACH message. You can safely call LabWindows/CVI library functions.

Additional Information

Library: Utility Library

Include file: utility.h

LabWindows/CVI compatibility: LabWindows/CVI 5.0 and later

Example

Refer to dll\basic\cvidll.cws for an example of using the CVIRTEHasBeenDetached function.

Was this information helpful?