FileAPI.h

Hi,

I am using Windows 7 64-bit and Visual Studio 2008 version 9.0.21022.8.

In short, I am looking for the header "FileAPI.h". My compiler tells me "Cannot open include file: 'FileAPI.h': No such file or directory"

Is there an alternate header I can attach? Or is this file already on my system somewhere? Is this header available on the internet for free download (anyone have a link)?

Separately, I am attempting to use the GetFileSize() function (for filesizes larger than 4GB) and the "HANDLE" type. The link below may provide more clarification.
http://msdn.microsoft.com/en-us/library/aa364957(VS.85).aspx

THANK YOU SO MUCH FOR YOUR HELP!!!
I should mention I do have a line to include Windows.h, but am getting the following errors:

error C3861: '_get_osfhandle': identifier not found
error C2660: 'GetFileSize' : function does not take 1 arguments
error C2065: 'hFile' : undeclared identifier

My assumption is that these errors will be gone if I can properly include FileAPI.h

THANK YOU ADVANCE FOR THE HELP!!!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <sys/stat.h> 
#include <Windows.h>
#include <WinBase.h>
#include <FileAPI.h>

int GetFileSize_example()	{

	const char *myFilename = "myfile.txt";
	FILE *pFile = fopen(myFilename,"r");

	if (pFile)
	{
		int fileNum = _fileno(pFile);
		HANDLE hFile = (HANDLE) _get_osfhandle(fileNum);
		GetFileSize(hFile);
	}

	printf ("\n\nSize of myfile.txt: %ld bytes.\n",hFile);

	return 0;
}
First of all, thank you for your response!

This link takes me to "GetDiskFreeSpace function" on the MSDN site. Did I miss a link somewhere for the FileAPI.h header file? Please advise. Thank you again!
Oops. Sorry. I thought that was the function you were using, my mistake.
FileAPI.h is a old header. It's nowhere to be found in a modern Windows SDK.

As the MSDN entries state, you should include Windows.h and let it include the other core headers.

FileAPI.h (include Windows.h);
WinBase.h on Windows Server 2008 R2, Windows 7, Windows Server 2008,
Windows Vista, Windows Server 2003, and Windows XP (include Windows.h) 

So you should strip down this

1
2
3
4
5
6
7
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <sys/stat.h> 
#include <Windows.h>
#include <WinBase.h>
#include <FileAPI.h> 


to

1
2
3
4
5
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <sys/stat.h> 
#include <Windows.h> 


Andy

PS The MSDN entry does also mention that GetFileSize (and GetFileSizeEx) is now defined in WinBase.h. But WinBase.h is included by Windows.h...
Last edited on
Ok thank you for your help. Will strip down the headers as you indicate.

Ok as you clearly see that I include the Windows.h header. Can you help me with the following errors (note that my code is pasted above in my 2nd entry)?

error C3861: '_get_osfhandle': identifier not found
error C2660: 'GetFileSize' : function does not take 1 arguments
error C2065: 'hFile' : undeclared identifier


I was assuming that they were related to FileAPI.h (a simple fix), but now that you have shed light on the fact that they should be in Windows.h - clearly that isn't the issue.

Would you have a look at the errors and the code and let me know your thoughts on how to fix these?

Again, thank you for your help!

Chech out their entries in MSDN

http://msdn.microsoft.com

e.g.

GetFileSize function

Applies to: desktop apps only

Retrieves the size of the specified file, in bytes.

It is recommended that you use GetFileSizeEx.

Syntax

C++

1
2
3
4
DWORD WINAPI GetFileSize(
  _In_       HANDLE hFile,
  _Out_opt_  LPDWORD lpFileSizeHigh
);


Etc, etc.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa364955%28v=vs.85%29.aspx

(Note that when they say "applies to desktop apps only", Microsoft means normal, old-school Win32 or Win64 programs as opposed to the new Metro style apps)
Last edited on
Topic archived. No new replies allowed.