I am trying to set some Edit boxes with SetDlgItemText() in WM_INITDIALOG in a Dialog Box. I have two pointers to wide character strings, buf and buf1, which are defined as global variables. Buf I fill with a GetDlgItemText command and buf1 I fill with a function I defined in some separate C file. Both strings I can print with the MessageBox line (so it doesn't matter if I use buf or buf1), but if I try to fill some Edit boxes with them, it only shows the correct text for buf and for buf1 I get the strange characters. I can't see what I am doing differently. The commands in the WM_INITDIALOG are exactly the same. The code where buf and buf1 are initialized in the OK button case of the same Dialog procedure. Does anybody understand what is going on?
Code:
case IDOK:
{
len = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT1));
if(len > 0)
{
buf = (LPTSTR)GlobalAlloc(GPTR, 2*(len + 1));
buf1 = (LPWSTR)GlobalAlloc(GPTR, 1024);
GetDlgItemText(hwnd, IDC_EDIT1, buf, 2*(len + 1));
buf1 = Calculate(hwnd, buf, buf1, len);
MessageBox(hwnd, buf1, (LPCTSTR)L"Warning!", MB_OK | MB_ICONINFORMATION);
return TRUE;
}
break;