09-28-2009 10:18 PM
……
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!
Solved! Go to Solution.
09-28-2009 11:43 PM
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?
09-29-2009 12:11 AM
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()
……
09-29-2009 03:51 AM
Roberto?
Hi,thanks for your help. The version Which i am using is CVI 8.0.
posia
09-29-2009 03:56 AM
markus kossmann ,
Thanks very much for your reply.
posia