Click to See Complete Forum and Search --> : Problems with extended file I/O API


sh_roohani
December 26th, 2002, 06:11 AM
Hi,

Extended file I/O API like CopyFileEx and GetFileSizeEx are recognized as Undeclared Identifier by VC++ 6.0 on Windows 2000 Pro, while inside MSDN I saw these functions to be usable on Win NT 4.0+. I have Service Pack 3.0 On my Windows 2000 and Service Pack 4.0 On My Visual Studio 6.0.

What could be the reason? VS does not allow to include Windows.h to MFC projects but the functions are declared in Winbase.h and included to Windows.h. Inclusion of Winbase.h also produces many redifinition errors. Consider that old file I/O API like CopyFile and GetFileSize work properly, but I need Ex functions because I'm working with video files with a special format which are usually tens of gigabytes.

Regards,

Shahram Roohani

galathaea
December 27th, 2002, 06:06 AM
I am a bit unclear as to what you are including. Are you including both windows.h and winbase.h or just one when you get the undeclared identifer error? If including either is not giving you the correct funcion type name definitions, then you can do one of two things. You can either download the most current SDK headers from Microsoft, or you can just get the functions directly from the kernel32 (GetModuleHandle, GetProcAddress). Also using the latter allows you to stay portable by not linking directly to the functions in your IAT, meaning you can provide mechanisms to disallow options that use the API when running on earlier OSes without getting load linking errors...

If you describe your problem a bit more, I am sure I could give more information.

DanM
December 28th, 2002, 08:05 PM
GetFileSizeEx and all the other *Ex functions are declared in winbase.h inside an #if :

#if(_WIN32_WINNT >= 0x0400)
...

WINBASEAPI
BOOL
WINAPI
GetFileSizeEx(
HANDLE hFile,
PLARGE_INTEGER lpFileSize
);
...
#endif

In order for your program to properly recognize these functions, you need _WIN32_WINNT to be defined as >= 0x0400.

You can just add the follwing line before including winbase.h :


#define _WIN32_WINNT 0x0400

or add the following to the C++/preprocessor section of your project:

_WIN32_WINNT=0x0401

Dan

DanM
December 28th, 2002, 08:06 PM
Sorry, the second one it is supposed to be:

_WIN32_WINNT=0x0400

:)

Dan

TheCPUWizard
December 28th, 2002, 08:25 PM
Changing these macros can have serious ramifications. The entire VC++ environment is (unfortunately) set up to have the proper references to the environment that the compiler is running on. This means that special care must be taken when developing a program on a W2K box hat is intended to run on a 98 box (or any other combination of OS versions).

_WIN32_WINNT should already be defined provided the machine is running NT4.0 or later (which includes W2K and XP). Therefore the header file should be enabling the function definitions [I am assuming that the OP is NOT talking about a linker error.

To confirm this use the following code:


#ifdef _WIN32_WINNT
#if (_WIN32_WINNT >= 0x0400)
#pragma message("Functions Should Be Enabled")
#else
#pragma message("Operating System Version Too OLD")
#endif
#else
#pragma message("Computer is Not Win32 NT Based")
#endif


Put this right before the header #incude. And try a compile. Let us know what message appears in the output window.

DanM
December 28th, 2002, 08:35 PM
MSDN:

For example, to use the features specifically marked for Windows 2000 in the header files, you need to explicitly define _WIN32_WINNT as 0x0500 or greater. You can define the symbols using the #define statement in each source file, or by specifying the /D_WIN32_WINNT=0x0500 compiler option supported by Visual C++.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sdkintro/sdkintro/using_the_sdk_headers.asp

Dan