Just a quick one
-
Guys how can i declare a varible of type char and then later in my program set the size of the char buffer to suite the size of the file being read into the buffer? C++
-
Guys how can i declare a varible of type char and then later in my program set the size of the char buffer to suite the size of the file being read into the buffer? C++
LPTSTR pszFileText;//this is the buffer
//....Then somewhere else where you are reading in the file content
DWORD dwFileSize;
//reading the file size
dwFileSize = ::GetFileSize(hFile, NULL);if(dwFileSize != INVALID_FILE_SIZE)
{
LPTSTR pszFileText;//Take note you are allocating memory here
HGLOBAL hGlobal = ::GlobalAlloc(GPTR, dwFileSize + 1);//lock memory
pszFileText = (LPTSTR)::GlobalLock(hGlobal);
if(pszFileText != NULL)
{
DWORD dwRead;
if(::ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL))
;
//... rest of the code
}
//... if you don't need the contents of the file any more do this//open the lock :)
::GlobalUnlock(hGlobal);//free memory allocated
::GlobalFree(hGlobal);
}Jesus Loves You and Me :)
--Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord
-
Guys how can i declare a varible of type char and then later in my program set the size of the char buffer to suite the size of the file being read into the buffer? C++
char *p; latter calculate how much memory you want, p = (char*) malloc(size);
-Prakash
-
Guys how can i declare a varible of type char and then later in my program set the size of the char buffer to suite the size of the file being read into the buffer? C++
char* buffer;
int fileSize = WhateverToGetFileSize();
buffer = new char[fileSize];
DoStuffWithBuffer(buffer);
delete[] buffer;