🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.ms-windows.programmer.tools.mfc
7 messages
7 total messages Started by iti Tue, 23 Jan 1996 23:26
HELP - CString conversion?
#33
Author: iti
Date: Tue, 23 Jan 1996 23:26
26 lines
1378 bytes

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-

Please send any advice you have for me to my EMail address:
	iti@netvision.net.il

Thanks
Yaakov
Re: HELP - CString conversion?
#34
Author: Richard Clarke
Date: Tue, 23 Jan 1996 21:18
46 lines
2000 bytes
In article <NEWTNews.16531.822443361.Postmaster@Jerusalem.netvision.net.il>
           iti@Jerusalem.netvision.net.il  writes:

> 
> 
> 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-
> 
> Please send any advice you have for me to my EMail address:
>         iti@netvision.net.il
> 
> Thanks
> Yaakov
> 
> 

Unless I am much mistaken, this should do what you want
 
  CString strTest;
  ((CEdit *)GetDlgItem(IDC_EDIT1))->GetWindowText(strTest);

I am not emailing this because the point of newsgroups is
to share information and benefit the developer community,
not to answer 1 developer's question.

Good luck!

-- 
Richard Clarke
Re: HELP - CString conversion?
#35
Author: John Vasquez
Date: Wed, 24 Jan 1996 18:28
1 lines
633 bytes
Your Right!!!
Re: HELP - CString conversion?
#37
Author: Adler
Date: Fri, 26 Jan 1996 07:40
27 lines
1473 bytes
iti@Jerusalem.netvision.net.il wrote:
>
>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 *'
>--------------------------------------------------------------

try:
 #define MAXLEN 256 
 CString callBuf;
 LPTSTR p;
 int msgLen;

 p=callBuf.GetBuffer(MAXLEN);
 msgLen = GetDlgItemText(IDC_EDIT1, p, MAXLEN);
 callBuf.ReleaseBuffer();

Andreas Adler
Re: HELP - CString conversion?
#38
Author: Marty Fried
Date: Sun, 28 Jan 1996 02:48
35 lines
2019 bytes
Once upon a time (OK, it was Tue, 23 Jan 96 16:26:35 PDT),
iti@Jerusalem.netvision.net.il wrote:
>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-
>
>Please send any advice you have for me to my EMail address:
cc:	iti@netvision.net.il

You can use a CString directly only if the function calls for a
constant char * (LPCSTR).  Otherwise, you can call
CString::GetBuffer(), which will return a pointer that you can modify;
but you must later call ReleaseBuffer() if you do indeed change it.
This is clearly explained in the documentation for CString.

_______________________________________________________
Marty Fried - mfried@linex.com     Press Enter to Exit
San Anselmo, CA                           -NT message
(MSVC4 + MFC) && (Win95 || NT);             
Re: HELP - CString conversion?
#39
Author: 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
Re: HELP - CString conversion?
#41
Author: Niels Ull Jacobsen
Date: Sun, 28 Jan 1996 11:54
42 lines
1727 bytes
Adler <Andreas.Adler@zxa.x400.basf-ag.de> writes:

>iti@Jerusalem.netvision.net.il wrote:
>>
>>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 *'
>>--------------------------------------------------------------

>try:
> #define MAXLEN 256 
> CString callBuf;
> LPTSTR p;
> int msgLen;

> p=callBuf.GetBuffer(MAXLEN);
> msgLen = GetDlgItemText(IDC_EDIT1, p, MAXLEN);
> callBuf.ReleaseBuffer();

Totally correct. Of course, you could just use the somewhat simpler

msgLen = GetDlgItemText(IDC_EDIT1, callBuf);





>Andreas Adler


-- 
   Niels Ull Jacobsen, Dep. of CS, U of Copenhagen (null@diku.dk)
   Roenne Alle 3 st.th, 2860 Soeborg, Denmark, tel. +45 39 66 39 86
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads