0

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.

Sossenbinder
  • 4,852
  • 5
  • 35
  • 78
  • Generally your attempt #2 is correct but you have a mess with ATL/WTL strings and hence the error. If you are building with ATL, your best solution would be to simply NOT use WTL string classes (define `_WTL_NO_CSTRING` in stdafx.h). – Roman R. Jan 31 '16 at 11:17

1 Answers1

1

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.

Vlad Feinstein
  • 10,960
  • 1
  • 12
  • 27
  • I'm actually trying to solve it via WTL. Is DDX and CString not a part of WTL-themed GUI-programming but rather MFC? The tutorial on codeproject I read had both of them explained as well. I'm currently only trying to do it via GetDlgItemText just for the sake of getting the job done. – Sossenbinder Jan 28 '16 at 07:23
  • EDIT: Just got home and tried this, this doesn't work for me. It might be due to the #define GetDlgItemText GetDlgItemTextA – Sossenbinder Jan 28 '16 at 16:40
  • What doesn't work? This code *should* work: `CString windowText; GetDlgItemText(IDC_LINKPASTEEDIT, windowText);`... What errors are you getting? – Vlad Feinstein Jan 28 '16 at 16:52
  • #define GetDlgItemText GetDlgItemTextA --- Error: No instance of overloaded function "*My class*::GetDlgItemTextA" matches the argument list. Argument types are: (int, WTL::CString) – Sossenbinder Jan 28 '16 at 16:56
  • Well, is your second parameter a `WTL::CString`? I never mixed MFC with WTL, but presume that without the namespace, `CString` is an MFC/ATL string. Try explicitly specifying `WTL::CString windowText;` [EDITED] Actually, it's the other way around: you *ARE* passing `WTL::CString` when another type is expected. What is the definition of your `GetDlgItemTextA` ? – Vlad Feinstein Jan 28 '16 at 17:18
  • I made it work, finally. See my edited post. Still feels very clunky and not WTL-like at all. I love how I tried to do it with the definition given in my WinUser.h file, and now it works while not trying to do it as the definition said, but rather with your method. Where do you find out all that WTL stuff by the way? I can barely find a documentation at all – Sossenbinder Jan 28 '16 at 17:20