LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Not found error message from LabVIEW runtime when called from VC++ with statically linked MFC

I have a dll built using LabVIEW 6i. I am calling the dll from a VC++ application. When the application loads I get an error pop-up 'cannot find LabVIEW runtime'. If I change the VC++ code to dynamically load MFC (using the loadlibrary function) or dynamically load the LabVIEW dll I created then the problem goes away. Only when both are loaded statically do I get the error message.

The target machine is running Win2K pro and has the LabVIEW runtime installed.

I do not want do dynamic loads as I need to call the dll from a legacy application. Are there any options to change the way LV links to MFC or to force the dll to find the LV runtime?

Alan Widmer
0 Kudos
Message 1 of 5
(6,836 Views)
Hi Alan-

I am a little confused about your "statically loaded dll" - how are you doing this in Visual C++? I thought all dlls are loaded dynamically, hence the "dynamically loaded library". For static loads, we usually create static libraries that are compiles into the exe at compile time vs runtim with the dll. The *.lib file LabVIEW 6 creates with its dll creation is an import library, it does not contain the guts of the module just the hooks to the dll (I think....).
Please correct me if I am wrong. I have attached a sample program that statically links MFC and dynamically links a dll created by LabVIEW and runs this in VC++. It does not call any MFC functions. The sample itself does nothing much, just a sample about how to pass numeric data types betwe
en LabVIEW and VC++.

Add information about how you are linking your static dll and I would love to look at it and help you solve this issue. Just a note - you might have to manually add the MFC to the VC++ project again under Project -> Settings.

good luck
ben schulte
national instruments
0 Kudos
Message 2 of 5
(6,836 Views)
Ben,

I have attached a ZIP of the files required to test a DLL from an MFC application. Or you can build the same application by following the instructions below. I used the numtest dll that you previously sent to me so there is no 'magic' in the LabVIEW or dll.

In VC++ select NEW. Pick the MFC AppWizard (MFC) to build an MFC application. In the wizard select
Project Name: MFCNumtest
Single Document
No database support
No Compound document support
Support for ActiveX
Default settings on the Features page
MFC Standard
MFC as a shared DLL

From the ResourceView of the project explorer, add an item Test to the IDR_MAINFRAME menu then add an item Go as a submenu item (with an ID of ID_TEST_GO)

Right click the new menu item and run the Class
Wizard. Click Add Function.. button to make a function OnTestGo()
Open MainFrm.cpp and scroll to the end of the file to see the skeleton for the OnTestGo function. In this function add a call to the LabVIEW dll. You will also need to add a reference to the .lib file and the usual extcode.h.

When you run the app you will see a window with the Test menu item. Select it and click Go to run the call to LabVIEW.

This all works great. If you now go to Project | Settings and on the general tab change the Microsoft Foundation Classes: item from 'Use MFC in a shared DLL' to 'Use MFC in a static library' rebuild ALL files in the project and run the app you get the error message:

System error 998 while loading the LabVIEW Run-Time Engine (C:\Program Files\National Instruments\shared\LabVIEW Run-Time\6.0\\lvrt.dll).
numtest requires a version 6.0 (or compatible) LabVIEW Run-Time Engine. Please contact the vendor of numtest to correct this problem.

I apologies for my slow response, g
ot distracted by some other issues.

Thanks for your help,

Alan Widmer.
0 Kudos
Message 3 of 5
(6,836 Views)
Hi Alan -
I sent an email to your associate, Patrick Kelly, further dealing with this issue. For others reading this thread, I will post the final resolution when we have one.

ben schulte
national instruments
0 Kudos
Message 4 of 5
(6,836 Views)
OK, this issue was several workarounds until this issue is resolved in a future release of LabVIEW-
1. Link with the DLL form of MFC.
2. Do not link with the .lib from the LV DLL, instead use LoadLibrary and GetProcAddress to dynamically load the DLL and call the function.
3. Use the VC delayload feature to make the LV DLL not get loaded until the first call is made into it. See VC help on "delayload" for information on setting this up. In a nutshell, under Project -> Settings -> Link add "delayimp.lib" to Object/library modules and in the the Project Options box append the following string:

/delayload:"sampleDLL.dll"

where sampleDLL.dll is the name of the dll you want to delayload.

ben schulte
national instruments
Message 5 of 5
(6,836 Views)