Convert 2.5 Gigabytes to LARGE_INTEGER in MemoryMapping Class
{This post is largely platform-dependent, but is being approved because
there are some non-platform-specific issues involved. Please restrict
replies to non-platform-specific issues. --mod}
Good afternoon, I am trying to write a C++ Memory Mapping class in VC+
+ 2008. Here is one of my constructors:
cMemoryMappedFile::cMemoryMappedFile(long FileSize_, OpenModes
OpenMode_,
AccessModes AccessMode_, ShareModes ShareMode_,
long Flags_,void *Security_,FILEHANDLE Template_) {
FileSize = FileSize_;
char* buffer = new char[BUFFER_SIZE]
DWORD dwRetVal = 0;
UINT uRetVal = 0;
DWORD dwPtr = 0;
BOOL isSetEndOfFile = FALSE;
char lpTempPathBuffer[MAX_PATH];
// Gets the temp path env string (no guarantee it's a valid
path).
dwRetVal = GetTempPath(MAX_PATH, // length of the buffer
lpTempPathBuffer); // buffer for path
if (dwRetVal > MAX_PATH || (dwRetVal == 0)){
throw cException(ERR_MEMORYMAPPING,"");
}
// Generates a temporary file name.
uRetVal = GetTempFileName(lpTempPathBuffer, // directory for tmp
files
TEXT("DEMO"), // temp file name
prefix
0, // create unique name
TempFileName); // buffer for name
if (uRetVal == 0)
{
throw cException(ERR_MEMORYMAPPING,lpTempPathBuffer);
}
// Creates the new file to write to for the upper-case version.
hFile = CreateFile((LPTSTR) TempFileName, // file name
AccessMode_, // open for write
0, // do not share
(SECURITY_ATTRIBUTES *)
Security_, // default security
OpenMode_, // CREATE_ALWAYS, //
overwrite existing
Flags_,// normal file
Template_); // no template
if (hFile == INVALID_HANDLE_VALUE)
{
throw cException(ERR_MEMORYMAPPING,TempFileName);
}
dwPtr = SetFilePointer(hFile,FileSize_,NULL,FileBegin);
if (dwPtr == INVALID_SET_FILE_POINTER){
throw cException(ERR_MEMORYMAPPING,TempFileName);
}
isSetEndOfFile = SetEndOfFile(hFile);
if (!isSetEndOfFile){
throw cException(ERR_MEMORYMAPPING,TempFileName);
}
hMapping=::CreateFileMapping(hFile,(SECURITY_ATTRIBUTES *)
Security_,PAGE_READWRITE,0,0,0);
if (hMapping==NULL)
throw cException(ERR_MEMORYMAPPING,TempFileName);
MapPtr = (void*)::MapViewOfFile( hMapping, FILE_MAP_WRITE |
FILE_MAP_READ, 0, 0, 0 );
if (MapPtr==NULL)
throw cException(ERR_MEMORYMAPPING,TempFileName);
delete [] buffer;
FilePath=new char[strlen(TempFileName)+1];
strcpy(FilePath,TempFileName);
}
I was testing this constructor yesterday with a FileSize of 2.3
Gigabytes when SetFilePointer returned INVALID_SET_FILE_POINTER.
Because the FileSize was greater than 2.0 Gigabytes I realized that I
had to modify the SetFilePointer function prototype to
SetFilePointer(hFile,((LARGE_INTEGER*) &Distance_)->LowPart,&
(((LARGE_INTEGER*) &Distance_)->HighPart),FileBegin);
My question is how convert 2.5 Gigabytes into to the LowPart and
HighPart members of the LARGE_INTEGER struct/union. Do I have to do
the conversion myself? In VC7, there was a largeint.h file which had a
function ConvertLongToLargeInteger. How do I emulate
ConvertLongToLargeInteger in Visual Studio C++ 2008? Thank you.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]