Search code examples
c++mfcwtl

How can I obtain the content of a Edit Control with WTL?


I've already read up on a few threads here on how to achieve that. I tried several answers but none worked so far. I simply want to get the content of a Edit control, given as CEdit in WTL, and save it into a preferably std::wstring, but I guess I can't get around using CString/TCHAR*.

Prerequisites:

ID of my control: IDC_LINKPASTEEDIT

Member variable IDC_LINKPASTEEDIT is assigned to via DDX MAP: m_linkPasteEdit

What I tried so far:

1.)

CString windowText;
GetDlgItemText(IDC_LINKPASTEEDIT, windowText, 1024);

-> Argument list error for GetDlgItemTextA (which is referred to by GetDlgItemText's DEFINE)

2.)

CString windowText;
m_linkPasteEdit.GetWindowText(windowText);

-> Another argument list error for GetDlgItemTextA

I can't quite figure out the correct list as well, as documentation is not existent and looking into the define I feel like my arguments should be correct.

Sadly I didn't find another resource, I even downloaded some html document WTL library, but it seems like CEdit isn't completely documented in there.

Any ideas?

EDIT:

Made it work in a very very weird fashion, which is not really WTL-like in my opinion, but it works at least.

1) - Change Multibyte charset to UNICODE in project settings

2) -

WCHAR windowText[1024]; 
GetDlgItemText(IDC_LINKPASTEEDIT, windowText, 1024);

Works with multibyte as well by using CHAR instead of WCHAR, but I prefer the wide way.


Solution

  • The CString, DDX and GetDlgItemText suggest that you are using MFC, NOT WTL - is that right?

    MFC's GetDlgItemText has two overloads:

    int GetDlgItemText(
       int nID,
       LPTSTR lpStr,
       int nMaxCount 
    ) const;
    int GetDlgItemText(
       int nID,
       CString& rString 
    ) const;
    

    and your call doesn't match either. Use CString's form, without the length.