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!

Re: Confused of LPBYTE lpBuffer - variable error <bad ptr> by Michael

Michael
Mon Aug 28 08:57:34 CDT 2006

You could
1) Check the return value from HeapAlloc. Do people still not check?
2) Read the WinCE help on HeapAlloc to find that HEAP_GENERATE_EXCEPTIONS is
unsupported.
3) Read the WinCE source (free download!) HeapAlloc calls
SetLastError(ERROR_INVALID_PARAMETER) if you pass in
HEAP_GENERATE_EXCEPTIONS.

--
Michael Salamone [eMVP]
Entrek Software, Inc.
www.entrek.com


"MIUSS" <miuss@seznam.cz> wrote in message
news:1156769821.924503.193280@74g2000cwt.googlegroups.com...
> 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!
>



Re: Confused of LPBYTE lpBuffer - variable error <bad ptr> by MIUSS

MIUSS
Tue Aug 29 02:11:13 CDT 2006


Michael J. Salamone wrote:
> You could
> 1) Check the return value from HeapAlloc. Do people still not check?
> 2) Read the WinCE help on HeapAlloc to find that HEAP_GENERATE_EXCEPTIONS is
> unsupported.
> 3) Read the WinCE source (free download!) HeapAlloc calls
> SetLastError(ERROR_INVALID_PARAMETER) if you pass in
> HEAP_GENERATE_EXCEPTIONS.
>
> --
> Michael Salamone [eMVP]
> Entrek Software, Inc.
> www.entrek.com


Thank you very much, that helps me at all! I was searching the fault
somewhere else and that's probably why I couldn't settle this trivial
problem out. I knew that CE doesn't support some features but I thought
that I would recieve some error report like otherwhile. But in this
case I didn't.

Have a nice day!