🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.ms-windows.programmer.tools.mfc
Article #39

Re: HELP - CString conversion?

#39
From: Huw Leonard
Date: Sun, 28 Jan 1996 05:13
51 lines
2484 bytes
In article <NEWTNews.16531.822443361.Postmaster@Jerusalem.netvision.net.il>, 
iti@Jerusalem.netvision.net.il says...
>
>When I try to read the text from a Edit Control (IDC_EDIT1) with the
>following code:
>
>--------------------------------------------------------------
>CString callBuf;
>int msgLen = GetDlgItemText(IDC_EDIT1, callBuf, sizeof(callBuf));
>--------------------------------------------------------------
>
>I get the following error:
>
>--------------------------------------------------------------
>error C2664: 'GetDlgItemText' : cannot convert parameter 2 from 'class 
>::CString ' to 'char __far *'
>--------------------------------------------------------------
>
>
>I am using Visual C++, how can I read the text directly into the CString?
>I know that I am doing something REAL STUPID so if you can be of any help-

If you are using CWnd::GetDlgItemText(), then the code is quite simple:

int msgLen=GetDlgItemText( IDC_EDIT1, callBuf );

The compiler error is generated because Visual C++ is trying to match on
one of the two over-rides:

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

(Taken directly from Visual C++ 4.0 help.) You are confusing the compiler
by providing a CString reference *AND* the integer.

'Course, all bets are off if you are _NOT_ using CWnd::GetDlgItemText().
If that's the case, you've got to either allocate a separate char* buffer,
or create a buffer inside the CString object with the GetBuffer() method,
which has the following prototype:

LPTSTR GetBuffer( int nMinBufLength );

Hope this helps.

-- 
____________________________________________________________
Huw Leonard
"To secure ourselves against defeat lies in our own hands, but the
opportunity of defeating the enemy is provided by the enemy himself.
Hence the saying: One may _know_ how to conquer without being able
to _do_ it." - Sun Tzu, The Art Of War
Technical Details
Message-ID: <4ef0lu$346@steel.interlog.com>
Path: arc1-ca.pugleaf.net!news.interlog.com!news
References: <NEWTNews.16531.822443361.Postmaster@Jerusalem.netvision.net.il>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.interlog.com!news
From: huw@interlog.com (Huw Leonard)
Newsgroups: comp.os.ms-windows.programmer.tools.mfc,comp.os.ms-windows.apps.compatibility.win95,comp.lang.c++
Subject: Re: HELP - CString conversion?
Date: 28 Jan 1996 05:13:34 GMT
Organization: InterLog Internet Services
Message-ID: <4ef0lu$346@steel.interlog.com>
References: <NEWTNews.16531.822443361.Postmaster@Jerusalem.netvision.net.il>
NNTP-Posting-Host: huw.interlog.com
X-Newsreader: WinVN 0.99.3