Hello again.
I have changed some code from ASCII to UNICODE so I have to use WCHAR instead of CHAR. What I am trying to do is to get the content of a RICHEDIT control into a WCHAR pointer for further use. In the ASCII version (where I use CHAR), it does work, but with WCHAR I am getting pointers troubles. My code is this:
// Global variables
HWND RichEditControl;
ULONG FileLength; // Length of the file
WCHAR FileContent; // Pointer for the content to be stored
GETTEXTLENGTHEX GetLengthMode; // GETTEXTLENGTHEX structure
GETTEXTEX GetTextMode; // GETTEXTEX structure
// WM_CREATE message
case WM_CREATE:
// Create the rich edit control and other controls...
GetLengthMode.flags = GTL_DEFAULT;
GetLengthMode.codepage = 1200; // UNICODE CODEPAGE
GetTextMode.flags = GT_DEFAULT;
GetTextMode.codepage = 1200; // UNICODE CODEPAGE
GetTextMode.lpDefaultChar = NULL;
GetTextMode.lpUsedDefChar = NULL;
break;
// WM_COMMAND message, when I press some button to get the text
case WM_COMMAND:
switch(LOWORD(Wparam)) {
case BTN_GETTEXT:
// I get the length of the RichEditControl content correctly
FileLength = SendMessage(
RichEditControl,
EM_GETTEXTLENGTHEX,
LPARAM(&GetLengthMode, 0)
);
// If RichEditControl not empty
if (FileLength>0) {
FileContent = new WCHAR[FileLength];
GetTextMode.cb = FileLength;
SendMessage(
RichEditControl,
EM_GETTEXTEX,
WPARAM(&GetTextMode),
LPARAM(&FileContent)
);
MessageBox(NULL, FileContent, L"RichEditControl Content", MB_OK);
}
break;
}
break;
When I click on BTN_GETTEXT I get a message box with no text, so I don't understand why I cannot get the text.
Some clues? Thanks!
Everything looks ok, except for line 34. FileLength is the length in characters, but it has to be converted to bytes. You have to multiply by sizeof(WCHAR). Other than that it should work, I guess.