Can somebody give me a handle on it?
Thanks
:)
Printable View
Can somebody give me a handle on it?
Thanks
:)
Try this.
Usage:Code:bool OpenFile(LPSTR sFileName, HWND hText) {
HANDLE hFile;
bool bSuccess;
LPSTR pszText;
DWORD dwLength;
DWORD dwRead;
hFile = CreateFile(sFileName, GENERIC_READ, NULL, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if ( !hFile )
return false;
dwLength = GetFileSize(hFile, NULL);
if(dwLength != 0xFFFF)
{
pszText = (char *)LocalAlloc(LPTR, dwLength + 1);
if (ReadFile(hFile, pszText, dwLength, &dwRead, NULL))
{
pszText[dwLength] = 0;
if( SetWindowText(hText, (LPCTSTR) pszText)) {
bSuccess = true;
}
}
LocalFree((HLOCAL) pszText);
}
else
{
MessageBox(NULL, "File cannot exceed 65535 bytes", "Error", MB_OK | MB_ICONEXCLAMATION);
bSuccess = false;
}
CloseHandle(hFile);
return bSuccess;
}
OpenFile("FileName", hwndEdit);
file handle, eh? how about a file pointer...
PHP Code:#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
void main( void )
{
FILE *fptr;
struct _stat buf;
int i;
char fnam[] = "myfile.txt";
i = _stat( fnam, &buf ); // get file information
// buf.st_size is now file len
char *filebuf = malloc(buf.st_size); // get a place to store file in memory
// check for malloc fail in good code
fptr = fopen(buffer);
if ( fread(filebuf, (size_t) buf.st_size, (size_t) buf.st_size, fptr) == buf.st_size) // read it all in
{
printf("%s\n","success");
}
free(filebuf);
fclose(fptr);
}
Thanks guys
:)
*cough* fstream.h *cough*Quote:
Originally posted by crptcblade
Can somebody give me a handle on it?
Thanks
:)