LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

File I/O problem in Visual C++ using "OpenFile"

"It seems that function "OpenFile" doesn't work in Visual C++ while it works in CVI.
Here is a simple testing program.

#include
#include
#include
void main()
{
int hFile;
hFile = OpenFile ("d:\\temp.txt", VAL_READ_WRITE, VAL_TRUNCATE, VAL_ASCII);
if (hFile == -1)
{
MessagePopup("Error", "File not opened");
}
else
{
const char buf[] = "Just Testing.";
WriteFile (hFile, buf, strlen(buf));
MessagePopup("Msg", "File opened and written.");
CloseFile (hFile);
}
}


When this program runs in Labwindows/CVI, the result is "File opened and written" and the buf is written to file. But when it runs in Visual
C++6.0, the result is "File not Opened".


It seemed that "OpenFile" doesn't work in Visual C++, while "fopen" works.


Does anybody know why?
Thanks."
0 Kudos
Message 1 of 6
(3,245 Views)
Hello

It might be a problem with the external libraries that CVI 6.0 provides for external compilers.Using GetFmtIOError(), i got error 2 returned ( "General I/O Failure" ).

I have filed a Corrective action request for this.

A workaround would be to compile your function into a dll from CVI, and then use the dll from Visual C++. I tried this and it seems to do the trick.

Hope this helps

Bilal Durrani
NI.
Bilal Durrani
NI
0 Kudos
Message 2 of 6
(3,245 Views)
Hi,

I could not reproduce this bug using VC 6.0. Make sure you are linking to cvirt.lib, in the extlib directory of cvi.

I created the VC project manually. If you created the VC project using the Measurement Studio Project Wizard, then you should see cvirt.lib in the link tab of the VC project settings dialog. If you do not see this library file, and instead see cvi_lvrt.lib or instrsup.lib, then replace cvi_lvrt.lib or instrsup.lib with cvirt.lib, and rebuild the project.

Best regards,
Mohan,
CVI
Message 3 of 6
(3,245 Views)
It seems that you are right.
The following is the list of lib file included in the link tab in project setting in visual c++:

"D:\MeasurementStudio\CVI\extlib\analysis.lib"
"D:\MeasurementStudio\CVI\extlib\cvi_lvrt.lib"
"D:\MeasurementStudio\CVI\extlib\cviauto.lib"
"D:\MeasurementStudio\CVI\extlib\cvisupp.lib"
"D:\MeasurementStudio\CVI\extlib\cviwmain.lib"
"D:\MeasurementStudio\CVI\extlib\dataskt.lib"
"D:\MeasurementStudio\CVI\extlib\easyio.lib"
"D:\MeasurementStudio\CVI\extlib\fpcustom.lib"
"D:\MeasurementStudio\CVI\extlib\gpib.lib"
"D:\MeasurementStudio\CVI\extlib\ivi.lib"
"D:\MeasurementStudio\CVI\extlib\ividcpwr.lib"
"D:\MeasurementStudio\CVI\extlib\ividmm.lib"
"D:\MeasurementStudio\CVI\extlib\ivifgen.lib"
"D:\MeasurementStud
io\CVI\extlib\iviscope.lib"
"D:\MeasurementStudio\CVI\extlib\iviswtch.lib"
"D:\MeasurementStudio\CVI\extlib\nivxi.lib"
"D:\MeasurementStudio\CVI\extlib\visa.lib"
"D:\MeasurementStudio\CVI\extlib\cvirt.lib"
kernel32.lib user32.lib gdi32.lib advapi32.lib

Both cvirt.lib and cvi_lvrt.lib are there. After the cvi_lvrt is deleted from the list and the rebuilt, the bug disappeared and I got the right result.

So I'd like to know what is the conflicts between cvirt.lib and cvi_lvrt.lib. If I don't include cvi_lvrt.lib, I am afraid some function could not be used and then what should I do?
0 Kudos
Message 4 of 6
(3,245 Views)
cvi_lvrt.lib is a subset of the cvirt.lib library. It is meant to be used in place of cvirt.lib when creating DLLs to be run on the LabVIEW RealTime platform. When you are linking to cvirt.lib, you will not lose any functions by removing cvi_lvrt.lib. The fact that both cvi_lvrt.lib and cvirt.lib are being added to the linker inputs is a bug, and we will fix it.

Thanks,
Mohan
0 Kudos
Message 5 of 6
(3,245 Views)
Thank you so much.
0 Kudos
Message 6 of 6
(3,245 Views)