Im using codeblocks ide, with GNU GCC compiler,
code WILL work in debug mode, but FAILS when you just execute the EXE without the debugger!

problem is, when using SF_TEXT|SFF_SELECTION options to stream in text, the callback function causes the program to crash, but only when NOT running the debugger, it's strange, anyone have any ideas?

here is my callback function...
Code:
DWORD CALLBACK RichEditEx::CBStreamIn(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
    string* str = (string*)(WPARAM)dwCookie;
    LONG len = str->length();
    if(len < 1)//when using SF_TEXT, for some reason we get a 2nd call after we are finished, so handle that situation
    {*pcb = len; return 0;}
    //{return 1;}//this does not work eithor

    if(len <= cb)//write last chunk
    {
        memcpy(pbBuff,str->data(),len);
        *pcb = len;
        delete str;
        //return 1; //cant do this, does not work
    }
    else//write chunks
    {
        memcpy(pbBuff,str->data(),cb);
        *pcb = cb;
        str->erase(0,cb);
    }

    return 0;
}

//my set text function
Code:
    SetSel(-1,-1);
    SetRTF(msg,SF_TEXT|SFF_SELECTION);//crashes when not in debug mode, something wrong with callback function when SF_TEXT is used
    char nl[] = "\r\n";
    SetRTF(nl,SF_TEXT|SFF_SELECTION);



//this does not have to be heap allocated
void RichEditEx::SetRTF(char* str, WPARAM options = SF_RTF)//options SF_RTF, SF_TEXT
{
    string* sstr = new string;
    sstr->append(str);//copy str into string
	EDITSTREAM es;
	es.dwError = 0;
	es.pfnCallback = CBStreamIn;
	es.dwCookie = (DWORD)(WPARAM)sstr;//pointer to string memory
    ::SendMessage(m_hWnd,EM_STREAMIN,options,(LPARAM)&es); //tell it to start stream in
    SetSel(-1,-1);//select end
}