Click to See Complete Forum and Search --> : Problem with GetDlgItemText.


Jyrno42
October 27th, 2009, 08:13 PM
I 'm trying to get the text of a dialogItem and save it to a file. The problem is that GetDlgItemText returns 0 and the strings empty. Anyhow, here's the code I'm using:



LPTSTR lpch = L"";
int s = GetDlgItemText(gg->TabCtrls[0].inside[0].cDialog, IDC_EDIT1, lpch, 128);

if(s == 0) DBGMSG(L":S"); // DBGMSG is just a MessageBox.
int lol = GetLastError(); // This is 0.



BTW: I'm using a simple WinApi wrapper class I made.

Arjay
October 27th, 2009, 08:25 PM
You need to allocate a buffer for the text. What you've allocated was a pointer.


TCHAR szBuffer[ 128 ] = { 0 };
int s = GetDlgItemText(gg->TabCtrls[0].inside[0].cDialog, IDC_EDIT1, szBuffer, 128);

VladimirF
October 28th, 2009, 10:41 AM
You need to allocate a buffer for the text. You are right, that buffer has to be allocated.
However, if that was the only problem - GetDlgItemText would not return 0.
See MSDN:
If the function fails, the return value is zero. To get extended error information, call GetLastError.