Click to See Complete Forum and Search --> : EM_GETLINE with c++ string


MasterDucky
November 5th, 2009, 09:03 AM
Hello!

Im trying to use EM_GETLINE with a c++ string instead of a dynamic char array.
It appears to function though i have some garbage sometimes at the end of the lines.
I cant see what am i doing wrong.


case GetText:
{
int iCount, i;
WORD iLength, iOffset;
string strLines;

//Get Number of Lines in Edit Field
iCount = SendMessage(hWin_2, EM_GETLINECOUNT, 0, 0);
if(!iCount) return 0;

for(i=0; i<iCount; i++)
{
iOffset = SendMessage(hWin_2, EM_LINEINDEX, i, 0);
iLength = (WORD)SendMessage(hWin_2, EM_LINELENGTH, iOffset, 0);
strLines = "";
strLines.resize(iLength + sizeof(WORD) + 1);

CopyMemory(&strLines[0], &iLength, sizeof(WORD)+1);
strLines += '\0';
SendMessage(hWin_2, EM_GETLINE, i, (LPARAM)&strLines[0]);
strLines += '\0';
SendMessage(hWin_1, LB_INSERTSTRING, -1, (LPARAM)&strLines[0]);
}



I can post the whole code if its not enough but the error must come from here because with a dynamic char array i dont have this problem. Thanks!

Codeplug
November 5th, 2009, 10:37 AM
You can't do that with strings, but you can with a vector. Use vector<char> and SendMessageA, or vector<wchar_t> and SendMessageW.

gg

MasterDucky
November 5th, 2009, 11:47 AM
Yes thanks Codeplug, i already did it with vector<char> but i was wondering if it was possible
with std::string.

Thanks for letting me know! :)