Re: First-chance exception 0xC0000005 Access violation by saving procedure



On 1 Srp, 08:27, "Peter Schottland" <anonym...@microsoft-
discussions.com> wrote:
CharsCount = GetWindowTextLength(hWndMainEditBox);
...
lpStringInEdit = (LPTSTR)HeapAlloc(GetProcessHeap(), 0,
CharsCount); //allocates memory for buffer

It looks like your allocated buffer is too small. The returned window text
length is the number of characters. In this special case: number of
WCHAR-characters! So you have to allocate (CharCount * sizeof(WCHAR)), or
better: (CharCount * sizeof(TCHAR)).

-peter

Hello Peter

Thank you for your post, although I already resolved my problem, it
was just what you say. I can not believe I couldn't see this fault. I
was looking for the error somewhere else and maybe I was little
confused with HeapAlloc (LPTSTR) - I supposed HeapAlloc creates the
string two times longer when return value is retyped by (LPTSTR).
Stupid thought:)))) I multiplied CharCount with sizeof WCHAR as you
refer and it worked out.

.


Loading