473,804 Members | 3,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CString to const char conversion

I'm getting the following error:

'strlen' : cannot convert parameter 1 from 'class CString' to 'const char *'

when I try to compile the following code:

HRESULT AnsiToUnicode(C String pszA, LPOLESTR* ppszW)
{
ULONG cCharacters;
DWORD dwError;
// If input is null then just return the same.
if (NULL == pszA)
{
*ppszW = NULL;
return NOERROR;
}
// Determine number of wide characters to be allocated for the
// Unicode string.
cCharacters = strlen(pszA)+1; <-------------------------
............... ...........
}

Any suggestions as to what the problem might be?

Fausto
Jul 22 '05 #1
9 12237
Fausto Lopez wrote:
I'm getting the following error:

'strlen' : cannot convert parameter 1 from 'class CString' to 'const char *'

when I try to compile the following code:

HRESULT AnsiToUnicode(C String pszA, LPOLESTR* ppszW)
{
ULONG cCharacters;
DWORD dwError;
// If input is null then just return the same.
if (NULL == pszA)
{
*ppszW = NULL;
return NOERROR;
}
// Determine number of wide characters to be allocated for the
// Unicode string.
cCharacters = strlen(pszA)+1; <-------------------------
............... ..........
}

Any suggestions as to what the problem might be?

Fausto


CString is not a part of the C++ language.
Many string classes have a method to convert to and
from C-Style strings. If you were using the std::string
class, you would use the std::sting::c_s tr() method.
See if the CString class has a similar method.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #2
Fausto Lopez wrote:
I'm getting the following error:

'strlen' : cannot convert parameter 1 from 'class CString' to 'const char *'

when I try to compile the following code:

HRESULT AnsiToUnicode(C String pszA, LPOLESTR* ppszW)
{
ULONG cCharacters;
DWORD dwError;
// If input is null then just return the same.
if (NULL == pszA)
{
*ppszW = NULL;
return NOERROR;
}
// Determine number of wide characters to be allocated for the
// Unicode string.
cCharacters = strlen(pszA)+1; <-------------------------
............... ..........
}

Any suggestions as to what the problem might be?


Nope. CString (IIRC) has 'operator const char*' defined, so it
should be picked up for the conversion.

Unfortunately, any more detail on this is off-topic here since
none of MFC classes are part of standard C++. Try the newsgroup
microsoft.publi c.vc.mfc or comp.os.ms-windows.program mer.tools.mfc

Victor
Jul 22 '05 #3
Fausto Lopez wrote:
I'm getting the following error:

'strlen' : cannot convert parameter 1 from 'class CString' to 'const char *'

Try http://groups.google.com to find a group qualified to discuss CString.
This group can only reliably discuss platform neutral C++.
when I try to compile the following code:

HRESULT AnsiToUnicode(C String pszA, LPOLESTR* ppszW)
{
Oookay. Nobody uses Hungarian Notation anymore. But "psz" means "pointer to
zero terminated string". This Department of Redundancy Department worked in
C using untypesafe conventions. CString is an object.
ULONG cCharacters;
DWORD dwError;
// If input is null then just return the same.
if (NULL == pszA)
This code treats pszA as a pointer, not an object. Try pszA.IsEmpty().
{
*ppszW = NULL;
return NOERROR;
}
// Determine number of wide characters to be allocated for the
// Unicode string.
cCharacters = strlen(pszA)+1; <-------------------------


What's wrong with pszA.GetLength( )?

I don't know what's wrong with pszA.operator LPCTSTR(), but you don't need
it. You could use a little more learning about both C++ and the MS library
supplying CString.

Also, MFC sucks, but you don't seem to be using all of it. Try WTL.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #4
Phlip wrote:
Fausto Lopez wrote:
// Determine number of wide characters to be allocated for the
// Unicode string.
cCharacters = strlen(pszA)+1; <-------------------------

I don't know what's wrong with pszA.operator LPCTSTR()...


There I go not reading the comments again...

If you have _UNICODE turned on then pszA has operator LPCWSTR(), and you
need MS Windows's private lstrlen() function.

But first clean up your attrocious style, and many problems like that will
just go away.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #5

"Phlip" <ph*******@yaho o.com> wrote in message
news:5l******** ********@newssv r32.news.prodig y.com...
Also, MFC sucks,


Why is that?
I have been using it many years with now real problems.
Jul 22 '05 #6
Juha Kettunen wrote:

Phlip wrote:

Also, MFC sucks,


Why is that?
I have been using it many years with now real problems.


When asked why I declare something sucks, I often point to issues writing
unit tests for it.

Such issues are typically symbolic of more important coupling issues.

In MFC, you can't create a window without coupling it, at run-time, to your
entire application. That breaks the principle "Test Isolation".

Try WTL to see what you have been missing.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #7
On Mon, 12 Jul 2004 22:06:04 GMT, "Juha Kettunen" <no******@email .com>
wrote:

"Phlip" <ph*******@yaho o.com> wrote in message
news:5l******* *********@newss vr32.news.prodi gy.com...
Also, MFC sucks,


Why is that?
I have been using it many years with now real problems.


MFC is a rather thin layer over Win32; it doesn't use proper object
oriented design. Obviously, it's perfectly usable in the same way that
Win32 is. However code using it is not as concise, understandable,
maintainable nor flexible as it that using better frameworks. Check
out almost any more recent GUI framework for better ways of doing
things.

Tom
Jul 22 '05 #8
tom_usenet wrote:
On Mon, 12 Jul 2004 22:06:04 GMT, "Juha Kettunen" <no******@email .com>
wrote:

"Phlip" <ph*******@yaho o.com> wrote in message
news:5l****** **********@news svr32.news.prod igy.com...
Also, MFC sucks,


Why is that?
I have been using it many years with now real problems.


MFC is a rather thin layer over Win32; it doesn't use proper object
oriented design.


Also it is designed around the capabilities of the C++ compilers of the
early nineties. So essentially C with classes; no templates, no
exceptions, no standard library...etc. Hence many ugly macro hacks.

--
Peter van Merkerk
peter.van.merke rk(at)dse.nl
Jul 22 '05 #9
In message <2l************ @uni-berlin.de>, Peter van Merkerk
<me*****@deadsp am.com> writes
tom_usenet wrote:
On Mon, 12 Jul 2004 22:06:04 GMT, "Juha Kettunen" <no******@email .com>
wrote:
"Phlip" <ph*******@yaho o.com> wrote in message
news:5l***** ***********@new ssvr32.news.pro digy.com...

Also, MFC sucks,

Why is that?
I have been using it many years with now real problems.

MFC is a rather thin layer over Win32; it doesn't use proper object
oriented design.


Also it is designed around the capabilities of the C++ compilers of the
early nineties. So essentially C with classes; no templates, no
exceptions, no standard library...etc. Hence many ugly macro hacks.

As opposed to, say, ATL, which is designed around the capabilities of a
certain (allegedly-)C++ compiler of the later nineties ;-(

--
Richard Herring
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
24543
by: Markus Hämmerli | last post by:
I ' ll tra to convert a Cstring to char* without success. I working in a Unicode enabled environment this is working in Unicode CString source = _T("TestString"); TCHAR *szSource = source.GetBuffer(0 ); but i need a char* and so this is not working CString source = _T("TestString");
3
1752
by: Terry chan | last post by:
Hi, How to convert String object to MFC CString? and from CString to String? Thanks! chan
5
14079
by: Tim Wong | last post by:
All: I am trying to convert a CString value to an unsigned char array. I found some code online that will allow me to compile, but when I try to print out...i get a whole mess. /*Begin Code*/ CString day("01"); unsigned char testDay;
3
9153
by: nsyforce | last post by:
What is the correct way to convert a const char* to a CString? I'm somewhat of a newbie and have tried several ways. While they all convert ok, I'm using a profiler that shows a memory leak for every option. Here's what I have tried: const char* test; test = getMyChar(); //CString myCString((LPCTSTR)test); //CString myCString(test); CString myCString = new CString(test);
2
13216
by: jt | last post by:
Looking for an example how to convert and CString to an ASCII character string. Any examples on how to do this? Thank you, jt
5
5385
by: Neo | last post by:
how convert CString to char *? regards, Mohammad Omer Nasir
0
2260
by: npotnis | last post by:
Hi All, I am trying to compile an existing C++ unamanaged application with the /clr switch in VS.Net 2003, as I need to use managed extensions in the code. In a cpp file I have the following code : CString strRet; COleVariant var = m_pRSTFormList->GetFieldValue("FormName"); if(var.vt == VT_BSTR) strRet = var.pbVal;
10
2796
by: d3x0xr | last post by:
---- Section 1 ---- ------ x.c int main( void ) { char **a; char const *const *b; b = a; // line(9)
12
12452
by: sas | last post by:
hi, i need that because the path functions for windows, like PathAppend and PathRemoveFileExt accept a writable zero terminated char*, but i didn't find that for std::string, with CString, i usually use GetBuffer for that LPTSTR CString::GetBuffer( int nMinBufLength )
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10315
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9140
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.