Admin Production ni-theme
Current Publication

Calling InitCVIRTE and CloseCVIRTE

LabWindows/CVI

Calling InitCVIRTE and CloseCVIRTE

If you link an executable or DLL in an external compiler, you must call the InitCVIRTE function at the beginning of your main, WinMain, or DllMain function.

For an executable using main as the entry point, your code must include the following segment:

#include <cvirte.h>
int main (int argc, char *argv[])
{

if (InitCVIRTE(0, argv, 0) == 0)

return (-1); /* out of memory */

/* your other code */

}

For an executable using WinMain as the entry point, your code must include the following segment:

#include <cvirte.h>

int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance LPSTR lpszCmdLine, int nCmdShow)

{

if (InitCVIRTE(hInstance, 0, 0) == 0)

return (-1); /* out of memory */

/* your other code */

}

For a DLL, you also have to call CloseCVIRTE in DllMain. The code must include the following segment:

#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 */

/* your other ATTACH code */

break;

case DLL_PROCESS_DETACH:

/* your other DETACH code */

CloseCVIRTE ();

break;

}

return 1;

}

Note  It is harmless, but unnecessary, to call these functions when you link your executable in LabWindows/CVI.