CString strType;
GetDlgItem(IDC_CONTROL_TYPES)->GetWindowText(strType);
I am receiving an assertion for the CString on the second line
and can't seem to determine the cause.
Thanks!
Roger
>Is the following legal in MFC?
>CString strType;
>GetDlgItem(IDC_CONTROL_TYPES)->GetWindowText(strType);
Yes it is. Could you be more specific as to which ASSERT you get? It
wouldn't happen to be GetDlgItem() which returns NULL due to a wrong
ID?
>I am receiving an assertion for the CString on the second line
>and can't seem to determine the cause.
>Thanks!
>Roger
--
Niels Ull Jacobsen, Dep. of CS, U of Copenhagen (nu...@diku.dk)
Roenne Alle 3 st.th, 2860 Soeborg, Denmark, tel. +45 39 66 39 86
>Is the following legal in MFC?
>CString strType;
>GetDlgItem(IDC_CONTROL_TYPES)->GetWindowText(strType);
>I am receiving an assertion for the CString on the second line
>and can't seem to determine the cause.
>Thanks!
>Roger
Have GetDlgItem assign to a variable, check the variable for NULL, THEN go for
the GetWindowText. Depending on where you're calling from, IDC_CONTROL_TYPES
may no exist yet. You can also do the same thing with GetDlgItemText().
-------------------
Kevin Hintergardt
ch...@halcyon.com
Welcome to the Information Goat Path
>>CString strType;
>>GetDlgItem(IDC_CONTROL_TYPES)->GetWindowText(strType);
>>I am receiving an assertion for the CString on the second line
>>and can't seem to determine the cause.
>Yes it is. Could you be more specific as to which ASSERT you get? It
>wouldn't happen to be GetDlgItem() which returns NULL due to a wrong
>ID?
That should give a gpf in debug mode.
Another Possibility:
IDC_CONTROL_TYPES is a combobox.You will get an assertion failed in
strcore1.cpp.If that is the case then use GetCurSel and GetLBText
to get the combo text(if that is what you want);
>
Sud
On the main CString help page in MFC help, there's a link
to CString Argument Passing. You *should* have been able
to find this:
"If a string is an input to a function, in most cases it
is best to declare the string function parameter as const char*.
Convert to a CString object as necessary within the function
using constructors and assignment operators. If the string contents
are to be changed by a function, declare the parameter as a
nonconstant CString reference (CString&)."
Also, see the GetBuffer/ReleaseBuffer members of CString.