LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Some problems occured when using "OpenFile" , "ReadFile",could someone help me please?

Solved!
Go to solution

…… 

FILE  *Pow_filehandle = NULL; 

int  nRead = 0;

 

Pow_filehandle = OpenFile ("Power_TestLowData.txt", VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_BINARY);

 

if (Pow_filehandle == NULL)
 {
  MessagePopup("","文件打开失败!");
 }


 nRead = ReadFile (Pow_filehandle, buf, strlen(buf));

……

 

when i compiled it ,some errors like these occurs:

 

 DataAcq_posia.c - 8 errors
  322, 57   Undeclared identifier 'VAL_READ_ONLY'.
  322, 70   Type error in argument 2 to `OpenFile'; found 'int' expected 'LPOFSTRUCT'.
  322, 72   Undeclared identifier 'VAL_OPEN_AS_IS'.
  322, 88   Undeclared identifier 'VAL_BINARY'.
  322, 98   Too many arguments to `OpenFile'.
  322, 99   Operands of = have illegal types 'pointer to FILE' and 'HFILE'.
  328, 54   Type error in argument 1 to `strlen'; found 'pointer to unsigned short' expected 'pointer to const char'.
  328, 56   Insufficient number of arguments to `ReadFile'.

Is there someboy can help me ?Thanks.

Regards!

0 Kudos
Message 1 of 5
(4,624 Views)
Solution
Accepted by topic author 宝宝熊

Hi,

it seems as if you have mixed up some instructions in your code...

OpenFile () is a command from the Formatting And I/O Library of CVI; it returns a integer handle. The FILE * pointer is returned from fopen () command from standard C library.

So you should decide which library are you intending to use and match the file handles to that.

I'm a little puzzled about the "Undeclared identified" errors: they should already be in your list of include files, or CVI should have prompted you to add the proper #include file when launching the application (BTW, it is formatio.h): which version of CVI are you using?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 5
(4,616 Views)

Some comments about  your code:

…… 

FILE  *Pow_filehandle = NULL; 

 

/* The FILE * type is used by ANSI C file functions and not by the NI formatio library specific file functions, which use a filehandle of type int */

int  nRead = 0;

 

Pow_filehandle = OpenFile ("Power_TestLowData.txt", VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_BINARY);

/*To get the prototype for  OpenFile()  and the declarations for VAL_READ_ONLY etc  , you have to #include <formatio.h>

and there is also a Windows SDK function named OpenFile() which you get if you #include <windows.h>.  You can't mix up NI's formatio library and the windows SDK */

 

if (Pow_filehandle == NULL)

// error condition for the filehandle is the value -1


 {
  MessagePopup("","文件打开失败!");
 }


 nRead = ReadFile (Pow_filehandle, buf, strlen(buf));

// There is also a windows SDK function named ReadFile()

……

Message 3 of 5
(4,613 Views)

Roberto?

 

Hi,thanks for your help. The version Which i am using is CVI 8.0. 

 

posia

0 Kudos
Message 4 of 5
(4,596 Views)

markus kossmann ,

 

Thanks  very much for your reply. 

 

posia

0 Kudos
Message 5 of 5
(4,593 Views)