The following code works fine:
int iLength = SendMessage(hWndEdit, EM_LINELENGTH, 0, 0);
if(iLength > 0) {
TCHAR* szBuffer = new TCHAR[iLength+1];
iLength = SendMessage(hWndEdit, EM_GETLINE, 0, (LPARAM)szBuffer);
szBuffer[iLength] = TEXT('\0');
MessageBox(hWnd, szBuffer, TEXT("Edit content"), MB_OK);
delete[] szBuffer;
}
Now I want to do the same thing using std::vector<TCHAR>:
int iLength = SendMessage(hWndEdit, EM_LINELENGTH, 0, 0);
if(iLength > 0) {
std::vector<TCHAR> data(iLength+1, TEXT('\0'));
iLength = SendMessage(hWndEdit, EM_GETLINE, 0, (LPARAM)&data[0]);
MessageBox(hWnd, &data[0], TEXT("Edit content"), MB_OK);
}
It compiles, but at iLength = SendMessage(hWndEdit, EM_GETLINE, 0, (LPARAM)&data[0]); the variable iLength will always be set to 0, and, accordingly, nothing will have been written into my vector.
What is the problem here? Thanks in advance.
From the documentation: