Problem with LPBYTE lpBuffer - I always get the variable error - <bad ptr>
Hello all!
I've got a problem with the variable LPBYTE lpBuffer - Debug watch
reports me that this variable has a bad ptr. Then it's the cause that
I'm not able to get success with loading my file which I need to see in
my dialog's edit-box.
This is the problem part of my code:
__________________________________________________________________________
HANDLE hFile;
DWORD dwSize;
DWORD dw;
LPBYTE lpBuffer = NULL;
lstrcpy(szSoubor, TEXT("\\temp\\test.txt"));
hFile = CreateFile(szSoubor, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0,
NULL);
if(hFile == INVALID_HANDLE_VALUE)
return;
dwSize = GetFileSize(hFile, NULL);
lpBuffer = (LPBYTE)HeapAlloc(GetProcessHeap(),
HEAP_GENERATE_EXCEPTIONS, dwSize+1);
if(!ReadFile(hFile, lpBuffer, dwSize, &dw, NULL)){
CloseHandle(hFile);
HeapFree(GetProcessHeap(), 0, lpBuffer);
return;
}
CloseHandle(hFile);
lpBuffer[dwSize] = 0;
SetDlgItemText(hwndDlg, IDC_EDIT1, (LPCTSTR)lpBuffer);
SetFocus(hwndDlg);
return;
___________________________________________________________
Did I do something wrong or did I forget something?
(I need the command <if(!ReadFile(...))> to get nonzero result.)
Thank you very much for any help!