LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

cvi rte initialization in a dll

I have a DLL I've created with CVI, and I use a DllMain function, and in the process attach section Ido an initCVIRTE call.  I can see where this might be necessary if the dll is invoked from a non-CVI module and the CVI rte's never been started.  But isn't the InitCVIRTE function always un-needed on a Windows system?

And even if it is needed, on process detach do I need to be shutting down the RTE with a CloseCVIRTE call?  If the invoking module is a CVI executable, won't this goof it up?  If it's a non-CVI module, what harm does it do to not call CloseCVIRTE?

I can't even find where in the CVI help / info it said to be making these calls in the first place.

Menchar
0 Kudos
Message 1 of 6
(3,299 Views)
Hi menchar,

The InitCVIRTE help topic in the CVI Help states that "You need InitCVIRTE only in executables or DLLs that you link using an external compiler. Otherwise, the function is harmless." 

The basic idea is that when you build an EXE or DLL within the CVI environment, we implicilty call InitCVIRTE (i.e. even if you don't).  However, when you are building a CVI DLL or EXE outside of CVI and in an external compiler (like VC), InitCVIRTE isn't implicitly called and thus you as the user must explicilty call it. 

The basic role of the InitCVIRTE function is to make the essential calls to startup code that is needed for your specific module (DLL, EXE).  This startup code is specific to your module and doesn't affect other modules using the CVI RTE.

The easiest example of its use case is when you build a CVI application in VC that uses a UIR.  In order for that UIR to hook up to the appropriate callbacks, you must create a UIR callbacks object or source file that will link into your EXE or DLL (i.e. Build >> External Compiler Support).  This object file or source file contains a list of the callback functions you specify in the .uir files in your project  When you load a panel or menu bar from the .uir file, the User Interface Library uses the list to link the objects in the panel or menu bar to their callback functions in your executable or DLL.  In this case, you must call the InitCVIRTE function at the beginning of your mainso that LabWindows/CVI run-time libraries can initialize the list of names from the source file.  This example is stated in the
Build >> External Compiler Support help topic.

CloseCVIRTE as well is only necessary if you are building CVI EXEs or DLLs in an external compiler. That function releases the memory that InitCVIRTE allocated. 

Hope that answers your questions. If not, let me know.

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 2 of 6
(3,271 Views)

Jonathan -

Thanks for the nice reply, that clarifies things.

I would infer that by "building with an external compiler" that doesn't mean when you're using an optimizing compiler (VCC, Intel Compiler) from within the CVI IDE?  Does the use of an optimizing compiler with CVI imply that that compiler's linker is then used as well?  I seem to recall that when I use the Intel compiler I need to explicitly link in its runtime library in the project so that makes me think it's the CVI linker being used.

Sounds like it's good practice to leave these calls in the DllMain in any case, so I'll put them back in.

Menchar

0 Kudos
Message 3 of 6
(3,264 Views)

BTW it looks like the CVI 8.5 help file entry for CloseCVIRTE is bungled up - you should call CloseCVIRTE at process detach, not InitCVIRTE.

 

Menchar

0 Kudos
Message 4 of 6
(3,253 Views)
Hi menchar,

Good catch on the CloseCVIRTE documentation. 

With regards to your "building with an external compiler" question, when you are within CVI (regardless if you are using an external compiler), you are using CVI's linker.

Does that clarify your question?

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 5 of 6
(3,246 Views)
Yes, thank you.
0 Kudos
Message 6 of 6
(3,236 Views)