Click here to Skip to main content
15,894,460 members

How to solve error: Heap block at 007A8530 modified at 007A860A past requested size of d2?

madharasan1 asked:

Open original thread
I am a newbie to C++. I was trying to convert the function here to set html unicode text to clipboard. This is what I have done so far:

C++
bool CopyHTML2(WCHAR *html ){
    wchar_t *buf = new wchar_t [400 + wcslen(html)];
    if(!buf) return false;

	static int cfid = 0;
    if(!cfid) cfid = RegisterClipboardFormat("HTML Format");

	    // Create a template string for the HTML header...
    wcscpy(buf,
        L"Version:0.9\r\n"
        L"StartHTML:00000000\r\n"
        L"EndHTML:00000000\r\n"
        L"StartFragment:00000000\r\n"
        L"EndFragment:00000000\r\n"
        L"<html><body>\r\n"
        L"<!--StartFragment -->\r\n");

    // Append the HTML...
    wcscat (buf, html);
    wcscat (buf, L"\r\n");
    // Finish up the HTML format...
    wcscat (buf,
        L"<!--EndFragment-->\r\n"
        L"</body>\r\n"
        L"</html>");

	wchar_t *ptr = wcsstr(buf, L"StartHTML");
	wsprintfW(ptr+10, L"%08u", wcsstr(buf, L"<html>") - buf);
	*(ptr+10+8) = L'\r';

    ptr = wcsstr(buf, L"EndHTML");
    wsprintfW(ptr+8, L"%08u", wcslen(buf));
    *(ptr+8+8) = '\r';

    ptr = wcsstr(buf, L"StartFragment");
    wsprintfW(ptr+14, L"%08u", wcsstr(buf, L"<!--StartFrag") - buf);
    *(ptr+14+8) = '\r';

    ptr = wcsstr(buf, L"EndFragment");
    wsprintfW(ptr+12, L"%08u", wcsstr(buf, L"<!--EndFrag") - buf);
    *(ptr+12+8) = '\r';

	// Open the clipboard...
    if(OpenClipboard(0)) {
        EmptyClipboard();
        HGLOBAL hText = GlobalAlloc(GMEM_MOVEABLE |GMEM_DDESHARE, wcslen(buf)+4);
        wchar_t *ptr = (wchar_t *)GlobalLock(hText);
        wcscpy(ptr, buf);
        GlobalUnlock(hText);
        SetClipboardData(cfid, hText);
        CloseClipboard();
        GlobalFree(hText);
    }

    // Clean up...
    //delete [] buf;
	return true;
}


I get the following error at SetClipboardData function:

HEAP[Project1.exe]: Heap block at 00378038 modified at 0037813E past requested size of fe
Project1.exe has triggered a breakpoint.

Any idea on how to solve this? Also is it the right way to do this? Or is there a simpler way to do it?

Thanks in advance for all your help.
Tags: C++, VC++

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900