Need help converting a CString to 8 bit Ascii char string

I having a problem passing an 8 bit char string to an SDK api.

What I am doing now is: "cs" is CString

char cPAGER_CODE[16];

strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this converstion 
correct?

The API to this SDK calls for an 8 bit char string to pass to it, but it 
doesn't like what I do.

Any help on my conversion above?

Thanks!
jt





0
jtsoft (29)
7/11/2005 10:11:50 PM
vc.mfc 33608 articles. 0 followers. Follow

20 Replies
926 Views

Similar Articles

[PageSpeed] 35

Do you have UNICODE defined?

If you do then you will have to convert from Unicode string,  if not - you 
can use cs directly

strcpy(cPager_Code, cs);

-- 
- Mark Randall
http://zetech.swehli.com

"jt" <jtsoft@hotmail.com> wrote in message 
news:G8CAe.190316$IO.79167@tornado.tampabay.rr.com...
>I having a problem passing an 8 bit char string to an SDK api.
>
> What I am doing now is: "cs" is CString
>
> char cPAGER_CODE[16];
>
> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this converstion 
> correct?
>
> The API to this SDK calls for an 8 bit char string to pass to it, but it 
> doesn't like what I do.
>
> Any help on my conversion above?
>
> Thanks!
> jt
>
>
>
>
> 


0
markyr1 (230)
7/11/2005 10:35:48 PM
You can use GetBuffer() in CString.

Tom

"jt" <jtsoft@hotmail.com> wrote in message 
news:G8CAe.190316$IO.79167@tornado.tampabay.rr.com...
>I having a problem passing an 8 bit char string to an SDK api.
>
> What I am doing now is: "cs" is CString
>
> char cPAGER_CODE[16];
>
> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this converstion 
> correct?
>
> The API to this SDK calls for an 8 bit char string to pass to it, but it 
> doesn't like what I do.
>
> Any help on my conversion above?
>
> Thanks!
> jt
>
>
>
>
> 


0
tserface (3861)
7/11/2005 11:02:32 PM
Its a const char* input on strcpy - LPCTSTR should do it fine unless UNICODE 
is defined.

Also, having to ReleaseBuffer is irritating.

-- 
- Mark Randall
http://zetech.swehli.com

"Tom Serface" <tserface@msn.com> wrote in message 
news:%23CnceymhFHA.576@tk2msftngp13.phx.gbl...
> You can use GetBuffer() in CString.
>
> Tom
>
> "jt" <jtsoft@hotmail.com> wrote in message 
> news:G8CAe.190316$IO.79167@tornado.tampabay.rr.com...
>>I having a problem passing an 8 bit char string to an SDK api.
>>
>> What I am doing now is: "cs" is CString
>>
>> char cPAGER_CODE[16];
>>
>> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this converstion 
>> correct?
>>
>> The API to this SDK calls for an 8 bit char string to pass to it, but it 
>> doesn't like what I do.
>>
>> Any help on my conversion above?
>>
>> Thanks!
>> jt
>>
>>
>>
>>
>>
>
> 


0
markyr1 (230)
7/11/2005 11:12:37 PM
Don't know if I have UNICODE defined. Where would it be if it was defined. I 
pick up this old project from another programmer.

How would I undefine UNICODE?

thanks,
jt


"Mark Randall" <markyr@REMOVETHISgoogle.ANDTHIScom> wrote in message 
news:OZhcljmhFHA.3448@TK2MSFTNGP12.phx.gbl...
> Do you have UNICODE defined?
>
> If you do then you will have to convert from Unicode string,  if not - you 
> can use cs directly
>
> strcpy(cPager_Code, cs);
>
> -- 
> - Mark Randall
> http://zetech.swehli.com
>
> "jt" <jtsoft@hotmail.com> wrote in message 
> news:G8CAe.190316$IO.79167@tornado.tampabay.rr.com...
>>I having a problem passing an 8 bit char string to an SDK api.
>>
>> What I am doing now is: "cs" is CString
>>
>> char cPAGER_CODE[16];
>>
>> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this converstion 
>> correct?
>>
>> The API to this SDK calls for an 8 bit char string to pass to it, but it 
>> doesn't like what I do.
>>
>> Any help on my conversion above?
>>
>> Thanks!
>> jt
>>
>>
>>
>>
>>
>
> 


0
jtsoft (29)
7/11/2005 11:33:56 PM
jt wrote:

> I having a problem passing an 8 bit char string to an SDK api.
> 
> What I am doing now is: "cs" is CString
> 
> char cPAGER_CODE[16];
> 
> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this converstion 
> correct?
> 
> The API to this SDK calls for an 8 bit char string to pass to it, but it 
> doesn't like what I do.
> 
> Any help on my conversion above?
> 
> Thanks!
> jt
> 
> 
> 
> 
> 

You haven't told us the most important detail.  Do you have an 8-bit 
char string in the CString?  This depends on whether your app is being 
built to use unicode or not.  (Unicode is 16 bit characters.)

If you are not using unicode then no casts are necessary:
strcpy(cPAGER_CODE, cs);

-- 
Scott McPhillips [VC++ MVP]

0
Scott
7/11/2005 11:56:45 PM
"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message 
news:unH7mvmhFHA.4000@TK2MSFTNGP12.phx.gbl...
> jt wrote:
>
>> I having a problem passing an 8 bit char string to an SDK api.
>>
>> What I am doing now is: "cs" is CString
>>
>> char cPAGER_CODE[16];
>>
>> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this converstion 
>> correct?
>>
>> The API to this SDK calls for an 8 bit char string to pass to it, but it 
>> doesn't like what I do.
>>
>> Any help on my conversion above?
>>
>> Thanks!
>> jt
>>
>>
>>
>>
>>
>
> You haven't told us the most important detail.  Do you have an 8-bit char 
> string in the CString?  This depends on whether your app is being built to 
> use unicode or not.  (Unicode is 16 bit characters.)
>
> If you are not using unicode then no casts are necessary:
> strcpy(cPAGER_CODE, cs);
>
> -- 
> Scott McPhillips [VC++ MVP]
>

I haven't specified UNICODE, so I assume its not, unless by MFC default the 
compiler does. With that in mind what and how do I do this just for this 1 
line of code?

Thanks,
jt


0
jtsoft (29)
7/12/2005 12:09:09 AM
You are royally screwed if you have UNICODE selected globally (project 
options) and the previous programmer has been using Unicode features.

You can tell if it is defined by putting

#ifdef UNICODE
#warning "Unicode defined! argh eeek booo"
#endif

And compiling, see if you get that message - if you do you have a minor 
problem, you are trying to mix 2 sets of strings - if you do not, 
strcpy(cWhatever, cs) will work.

Cooincidently, strcpy itself is a bad idea, try strncpy (the strn functions 
'prevent' buffer overflows), and if you have one CString, you might as well 
make them all CStrings.

-- 
- Mark Randall
http://zetech.swehli.com

"jt" <jtsoft@hotmail.com> wrote in message 
news:ElDAe.229251$w15.228118@tornado.tampabay.rr.com...
> Don't know if I have UNICODE defined. Where would it be if it was defined. 
> I pick up this old project from another programmer.
>
> How would I undefine UNICODE?
>
> thanks,
> jt 


0
markyr1 (230)
7/12/2005 1:19:14 AM
It has _MBCS defined as 1 of the compiler switches.

jt



"Mark Randall" <markyr@REMOVETHISgoogle.ANDTHIScom> wrote in message 
news:uULw6%23nhFHA.3656@TK2MSFTNGP09.phx.gbl...
> You are royally screwed if you have UNICODE selected globally (project 
> options) and the previous programmer has been using Unicode features.
>
> You can tell if it is defined by putting
>
> #ifdef UNICODE
> #warning "Unicode defined! argh eeek booo"
> #endif
>
> And compiling, see if you get that message - if you do you have a minor 
> problem, you are trying to mix 2 sets of strings - if you do not, 
> strcpy(cWhatever, cs) will work.
>
> Cooincidently, strcpy itself is a bad idea, try strncpy (the strn 
> functions 'prevent' buffer overflows), and if you have one CString, you 
> might as well make them all CStrings.

> -- 
> - Mark Randall
> http://zetech.swehli.com
>
> "jt" <jtsoft@hotmail.com> wrote in message 
> news:ElDAe.229251$w15.228118@tornado.tampabay.rr.com...
>> Don't know if I have UNICODE defined. Where would it be if it was 
>> defined. I pick up this old project from another programmer.
>>
>> How would I undefine UNICODE?
>>
>> thanks,
>> jt
>
> 


0
jtsoft (29)
7/12/2005 1:23:05 AM
"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message 
news:unH7mvmhFHA.4000@TK2MSFTNGP12.phx.gbl...
> jt wrote:
>
>> I having a problem passing an 8 bit char string to an SDK api.
>>
>> What I am doing now is: "cs" is CString
>>
>> char cPAGER_CODE[16];
>>
>> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this converstion 
>> correct?
>>
>> The API to this SDK calls for an 8 bit char string to pass to it, but it 
>> doesn't like what I do.
>>
>> Any help on my conversion above?
>>
>> Thanks!
>> jt
>>
>>
>>
>>
>>
>
> You haven't told us the most important detail.  Do you have an 8-bit char 
> string in the CString?  This depends on whether your app is being built to 
> use unicode or not.  (Unicode is 16 bit characters.)
>
> If you are not using unicode then no casts are necessary:
> strcpy(cPAGER_CODE, cs);
>
> -- 
> Scott McPhillips [VC++ MVP]
>

The compiler has _MBCS defined. If I take this out then can I use the 
strcpy(cPAGER_CODE,cs) ?

This will be copied then to an 8 bit char string?


jt


0
jtsoft (29)
7/12/2005 1:44:52 AM
Try :-

TCHAR cPAGER_CODE[16];
_tcscpy(cPAGER_CODE, cs);

-- 
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com


"jt" <jtsoft@hotmail.com> wrote in message 
news:G8CAe.190316$IO.79167@tornado.tampabay.rr.com...
>I having a problem passing an 8 bit char string to an SDK api.
>
> What I am doing now is: "cs" is CString
>
> char cPAGER_CODE[16];
>
> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this converstion 
> correct?
>
> The API to this SDK calls for an 8 bit char string to pass to it, but it 
> doesn't like what I do.
>
> Any help on my conversion above?
>
> Thanks!
> jt
>
>
>
>
> 


0
nish (347)
7/12/2005 3:55:50 AM
Would that make it a 8 bit character string?? Is TCHAR 8 bit?

jt


"Nishant Sivakumar" <nish@nospam.asianetindia.com> wrote in message 
news:eN57eWphFHA.3732@TK2MSFTNGP10.phx.gbl...
> Try :-
>
> TCHAR cPAGER_CODE[16];
> _tcscpy(cPAGER_CODE, cs);
>
> -- 
> Regards,
> Nish [VC++ MVP]
> http://www.voidnish.com
> http://blog.voidnish.com
>
>
> "jt" <jtsoft@hotmail.com> wrote in message 
> news:G8CAe.190316$IO.79167@tornado.tampabay.rr.com...
>>I having a problem passing an 8 bit char string to an SDK api.
>>
>> What I am doing now is: "cs" is CString
>>
>> char cPAGER_CODE[16];
>>
>> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this converstion 
>> correct?
>>
>> The API to this SDK calls for an 8 bit char string to pass to it, but it 
>> doesn't like what I do.
>>
>> Any help on my conversion above?
>>
>> Thanks!
>> jt
>>
>>
>>
>>
>>
>
> 


0
jtsoft (29)
7/12/2005 4:07:59 AM
TCHAR maps to char in non-Unicode builds and to a wchar_t in a Unicode 
build.

If you really need a char string, use the T2A macro to convert the TCHAR 
string to a char string.

USES_CONVERSION;
.. . .
char  cPAGER_CODE[16];
_tcscpy(cPAGER_CODE, T2A(cs) );

-- 
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com


"jt" <jtsoft@hotmail.com> wrote in message 
news:zmHAe.190438$IO.87468@tornado.tampabay.rr.com...
> Would that make it a 8 bit character string?? Is TCHAR 8 bit?
>
> jt
>
>
> "Nishant Sivakumar" <nish@nospam.asianetindia.com> wrote in message 
> news:eN57eWphFHA.3732@TK2MSFTNGP10.phx.gbl...
>> Try :-
>>
>> TCHAR cPAGER_CODE[16];
>> _tcscpy(cPAGER_CODE, cs);
>>
>> -- 
>> Regards,
>> Nish [VC++ MVP]
>> http://www.voidnish.com
>> http://blog.voidnish.com
>>
>>
>> "jt" <jtsoft@hotmail.com> wrote in message 
>> news:G8CAe.190316$IO.79167@tornado.tampabay.rr.com...
>>>I having a problem passing an 8 bit char string to an SDK api.
>>>
>>> What I am doing now is: "cs" is CString
>>>
>>> char cPAGER_CODE[16];
>>>
>>> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this converstion 
>>> correct?
>>>
>>> The API to this SDK calls for an 8 bit char string to pass to it, but it 
>>> doesn't like what I do.
>>>
>>> Any help on my conversion above?
>>>
>>> Thanks!
>>> jt
>>>
>>>
>>>
>>>
>>>
>>
>>
>
> 


0
nish (347)
7/12/2005 4:17:48 AM
My "cs" is defined as CString not TCHAR.

CString cs;
char cPAGER_CODE[16];

_tcscpy(cPAGER_CODE, T2A(cs) );

Will this work then?

Thank you,
jt


Will this macro still work with a Cstring
"Nishant Sivakumar" <nish@nospam.asianetindia.com> wrote in message 
news:eOCIviphFHA.1052@TK2MSFTNGP10.phx.gbl...
> TCHAR maps to char in non-Unicode builds and to a wchar_t in a Unicode 
> build.
>
> If you really need a char string, use the T2A macro to convert the TCHAR 
> string to a char string.
>
> USES_CONVERSION;
> . . .
> char  cPAGER_CODE[16];
> _tcscpy(cPAGER_CODE, T2A(cs) );
>
> -- 
> Regards,
> Nish [VC++ MVP]
> http://www.voidnish.com
> http://blog.voidnish.com
>
>
> "jt" <jtsoft@hotmail.com> wrote in message 
> news:zmHAe.190438$IO.87468@tornado.tampabay.rr.com...
>> Would that make it a 8 bit character string?? Is TCHAR 8 bit?
>>
>> jt
>>
>>
>> "Nishant Sivakumar" <nish@nospam.asianetindia.com> wrote in message 
>> news:eN57eWphFHA.3732@TK2MSFTNGP10.phx.gbl...
>>> Try :-
>>>
>>> TCHAR cPAGER_CODE[16];
>>> _tcscpy(cPAGER_CODE, cs);
>>>
>>> -- 
>>> Regards,
>>> Nish [VC++ MVP]
>>> http://www.voidnish.com
>>> http://blog.voidnish.com
>>>
>>>
>>> "jt" <jtsoft@hotmail.com> wrote in message 
>>> news:G8CAe.190316$IO.79167@tornado.tampabay.rr.com...
>>>>I having a problem passing an 8 bit char string to an SDK api.
>>>>
>>>> What I am doing now is: "cs" is CString
>>>>
>>>> char cPAGER_CODE[16];
>>>>
>>>> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this converstion 
>>>> correct?
>>>>
>>>> The API to this SDK calls for an 8 bit char string to pass to it, but 
>>>> it doesn't like what I do.
>>>>
>>>> Any help on my conversion above?
>>>>
>>>> Thanks!
>>>> jt
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
> 


0
jtsoft (29)
7/12/2005 5:16:33 AM
Yep, CString will cast to LPCTSTR - so it should work.

-- 
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com


"jt" <jtsoft@hotmail.com> wrote in message 
news:RmIAe.190444$IO.54648@tornado.tampabay.rr.com...
> My "cs" is defined as CString not TCHAR.
>
> CString cs;
> char cPAGER_CODE[16];
>
> _tcscpy(cPAGER_CODE, T2A(cs) );
>
> Will this work then?
>
> Thank you,
> jt
>
>
> Will this macro still work with a Cstring
> "Nishant Sivakumar" <nish@nospam.asianetindia.com> wrote in message 
> news:eOCIviphFHA.1052@TK2MSFTNGP10.phx.gbl...
>> TCHAR maps to char in non-Unicode builds and to a wchar_t in a Unicode 
>> build.
>>
>> If you really need a char string, use the T2A macro to convert the TCHAR 
>> string to a char string.
>>
>> USES_CONVERSION;
>> . . .
>> char  cPAGER_CODE[16];
>> _tcscpy(cPAGER_CODE, T2A(cs) );
>>
>> -- 
>> Regards,
>> Nish [VC++ MVP]
>> http://www.voidnish.com
>> http://blog.voidnish.com
>>
>>
>> "jt" <jtsoft@hotmail.com> wrote in message 
>> news:zmHAe.190438$IO.87468@tornado.tampabay.rr.com...
>>> Would that make it a 8 bit character string?? Is TCHAR 8 bit?
>>>
>>> jt
>>>
>>>
>>> "Nishant Sivakumar" <nish@nospam.asianetindia.com> wrote in message 
>>> news:eN57eWphFHA.3732@TK2MSFTNGP10.phx.gbl...
>>>> Try :-
>>>>
>>>> TCHAR cPAGER_CODE[16];
>>>> _tcscpy(cPAGER_CODE, cs);
>>>>
>>>> -- 
>>>> Regards,
>>>> Nish [VC++ MVP]
>>>> http://www.voidnish.com
>>>> http://blog.voidnish.com
>>>>
>>>>
>>>> "jt" <jtsoft@hotmail.com> wrote in message 
>>>> news:G8CAe.190316$IO.79167@tornado.tampabay.rr.com...
>>>>>I having a problem passing an 8 bit char string to an SDK api.
>>>>>
>>>>> What I am doing now is: "cs" is CString
>>>>>
>>>>> char cPAGER_CODE[16];
>>>>>
>>>>> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this 
>>>>> converstion correct?
>>>>>
>>>>> The API to this SDK calls for an 8 bit char string to pass to it, but 
>>>>> it doesn't like what I do.
>>>>>
>>>>> Any help on my conversion above?
>>>>>
>>>>> Thanks!
>>>>> jt
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
> 


0
nish (347)
7/12/2005 5:59:49 AM
Sorry, didn't get that from your initial message.  Sometimes throwing out 
ideas sparks other ideas.

You're right that the conversion should work.  What does "doesn't like what 
I do" mean?  Is there a specific compile error?

Tom

"Mark Randall" <markyr@REMOVETHISgoogle.ANDTHIScom> wrote in message 
news:uzeIK4mhFHA.272@TK2MSFTNGP15.phx.gbl...
> Its a const char* input on strcpy - LPCTSTR should do it fine unless 
> UNICODE is defined.
>
> Also, having to ReleaseBuffer is irritating.
>
> -- 
> - Mark Randall


0
tserface (3861)
7/12/2005 3:37:03 PM
Sorry, meant "his" original post...

ReleaseBuffer is not irritating if a char * is required in the call (plus 
you only have to do it if you modified the string).

Tom

"Mark Randall" <markyr@REMOVETHISgoogle.ANDTHIScom> wrote in message 
news:uzeIK4mhFHA.272@TK2MSFTNGP15.phx.gbl...
> Its a const char* input on strcpy - LPCTSTR should do it fine unless 
> UNICODE is defined.
>
> Also, having to ReleaseBuffer is irritating.
>
> -- 


0
tserface (3861)
7/12/2005 3:38:39 PM
LPCTSTR is const TCHAR, which is unicode is not defined is char and matches 
the direct type required for the second argument of strcpy.

Whenever you pass a string, it should always be made const if you can, which 
is how its passed in strcpy.

-- 
- Mark Randall
http://zetech.swehli.com

"Tom Serface" <tserface@msn.com> wrote in message 
news:OtEpGfvhFHA.1968@TK2MSFTNGP14.phx.gbl...
> Sorry, meant "his" original post...
>
> ReleaseBuffer is not irritating if a char * is required in the call (plus 
> you only have to do it if you modified the string).
>
> Tom 


0
markyr1 (230)
7/12/2005 3:50:49 PM
Sorry, but your T2A(Did not work). Would not compile.

I had to do this: strcpy(cPAGER_CODE, T2A((char *) (LPCSTR) cs));

That compiled.

So with my original code I posted it was doing the same thing I am doing 
now:
    strcpy(cPAGER_CODE, T2A((char *) (LPCSTR) cs));

But, it still did not do what I needed is a convertion to
8 bit ascii string. How can I do this?

jt


"Nishant Sivakumar" <nish@nospam.asianetindia.com> wrote in message 
news:%23RFM4bqhFHA.2840@tk2msftngp13.phx.gbl...
> Yep, CString will cast to LPCTSTR - so it should work.
>
> -- 
> Regards,
> Nish [VC++ MVP]
> http://www.voidnish.com
> http://blog.voidnish.com
>
>
> "jt" <jtsoft@hotmail.com> wrote in message 
> news:RmIAe.190444$IO.54648@tornado.tampabay.rr.com...
>> My "cs" is defined as CString not TCHAR.
>>
>> CString cs;
>> char cPAGER_CODE[16];
>>
>> _tcscpy(cPAGER_CODE, T2A(cs) );
>>
>> Will this work then?
>>
>> Thank you,
>> jt
>>
>>
>> Will this macro still work with a Cstring
>> "Nishant Sivakumar" <nish@nospam.asianetindia.com> wrote in message 
>> news:eOCIviphFHA.1052@TK2MSFTNGP10.phx.gbl...
>>> TCHAR maps to char in non-Unicode builds and to a wchar_t in a Unicode 
>>> build.
>>>
>>> If you really need a char string, use the T2A macro to convert the TCHAR 
>>> string to a char string.
>>>
>>> USES_CONVERSION;
>>> . . .
>>> char  cPAGER_CODE[16];
>>> _tcscpy(cPAGER_CODE, T2A(cs) );
>>>
>>> -- 
>>> Regards,
>>> Nish [VC++ MVP]
>>> http://www.voidnish.com
>>> http://blog.voidnish.com
>>>
>>>
>>> "jt" <jtsoft@hotmail.com> wrote in message 
>>> news:zmHAe.190438$IO.87468@tornado.tampabay.rr.com...
>>>> Would that make it a 8 bit character string?? Is TCHAR 8 bit?
>>>>
>>>> jt
>>>>
>>>>
>>>> "Nishant Sivakumar" <nish@nospam.asianetindia.com> wrote in message 
>>>> news:eN57eWphFHA.3732@TK2MSFTNGP10.phx.gbl...
>>>>> Try :-
>>>>>
>>>>> TCHAR cPAGER_CODE[16];
>>>>> _tcscpy(cPAGER_CODE, cs);
>>>>>
>>>>> -- 
>>>>> Regards,
>>>>> Nish [VC++ MVP]
>>>>> http://www.voidnish.com
>>>>> http://blog.voidnish.com
>>>>>
>>>>>
>>>>> "jt" <jtsoft@hotmail.com> wrote in message 
>>>>> news:G8CAe.190316$IO.79167@tornado.tampabay.rr.com...
>>>>>>I having a problem passing an 8 bit char string to an SDK api.
>>>>>>
>>>>>> What I am doing now is: "cs" is CString
>>>>>>
>>>>>> char cPAGER_CODE[16];
>>>>>>
>>>>>> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this 
>>>>>> converstion correct?
>>>>>>
>>>>>> The API to this SDK calls for an 8 bit char string to pass to it, but 
>>>>>> it doesn't like what I do.
>>>>>>
>>>>>> Any help on my conversion above?
>>>>>>
>>>>>> Thanks!
>>>>>> jt
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
> 


0
jtsoft (29)
7/12/2005 11:47:34 PM
Add
USES_CONVERSION;

before your call to T2A

Drew

"jt" <jtsoft@hotmail.com> wrote in message 
news:qEYAe.152334$VH2.133160@tornado.tampabay.rr.com...
> Sorry, but your T2A(Did not work). Would not compile.
>
> I had to do this: strcpy(cPAGER_CODE, T2A((char *) (LPCSTR) cs));
>
> That compiled.
>
> So with my original code I posted it was doing the same thing I am doing 
> now:
>    strcpy(cPAGER_CODE, T2A((char *) (LPCSTR) cs));
>
> But, it still did not do what I needed is a convertion to
> 8 bit ascii string. How can I do this?
>
> jt
>
>
> "Nishant Sivakumar" <nish@nospam.asianetindia.com> wrote in message 
> news:%23RFM4bqhFHA.2840@tk2msftngp13.phx.gbl...
>> Yep, CString will cast to LPCTSTR - so it should work.
>>
>> -- 
>> Regards,
>> Nish [VC++ MVP]
>> http://www.voidnish.com
>> http://blog.voidnish.com
>>
>>
>> "jt" <jtsoft@hotmail.com> wrote in message 
>> news:RmIAe.190444$IO.54648@tornado.tampabay.rr.com...
>>> My "cs" is defined as CString not TCHAR.
>>>
>>> CString cs;
>>> char cPAGER_CODE[16];
>>>
>>> _tcscpy(cPAGER_CODE, T2A(cs) );
>>>
>>> Will this work then?
>>>
>>> Thank you,
>>> jt
>>>
>>>
>>> Will this macro still work with a Cstring
>>> "Nishant Sivakumar" <nish@nospam.asianetindia.com> wrote in message 
>>> news:eOCIviphFHA.1052@TK2MSFTNGP10.phx.gbl...
>>>> TCHAR maps to char in non-Unicode builds and to a wchar_t in a Unicode 
>>>> build.
>>>>
>>>> If you really need a char string, use the T2A macro to convert the 
>>>> TCHAR string to a char string.
>>>>
>>>> USES_CONVERSION;
>>>> . . .
>>>> char  cPAGER_CODE[16];
>>>> _tcscpy(cPAGER_CODE, T2A(cs) );
>>>>
>>>> -- 
>>>> Regards,
>>>> Nish [VC++ MVP]
>>>> http://www.voidnish.com
>>>> http://blog.voidnish.com
>>>>
>>>>
>>>> "jt" <jtsoft@hotmail.com> wrote in message 
>>>> news:zmHAe.190438$IO.87468@tornado.tampabay.rr.com...
>>>>> Would that make it a 8 bit character string?? Is TCHAR 8 bit?
>>>>>
>>>>> jt
>>>>>
>>>>>
>>>>> "Nishant Sivakumar" <nish@nospam.asianetindia.com> wrote in message 
>>>>> news:eN57eWphFHA.3732@TK2MSFTNGP10.phx.gbl...
>>>>>> Try :-
>>>>>>
>>>>>> TCHAR cPAGER_CODE[16];
>>>>>> _tcscpy(cPAGER_CODE, cs);
>>>>>>
>>>>>> -- 
>>>>>> Regards,
>>>>>> Nish [VC++ MVP]
>>>>>> http://www.voidnish.com
>>>>>> http://blog.voidnish.com
>>>>>>
>>>>>>
>>>>>> "jt" <jtsoft@hotmail.com> wrote in message 
>>>>>> news:G8CAe.190316$IO.79167@tornado.tampabay.rr.com...
>>>>>>>I having a problem passing an 8 bit char string to an SDK api.
>>>>>>>
>>>>>>> What I am doing now is: "cs" is CString
>>>>>>>
>>>>>>> char cPAGER_CODE[16];
>>>>>>>
>>>>>>> strcpy(cPAGER_CODE, (char *) (LPCSTR) cs);  <-------is this 
>>>>>>> converstion correct?
>>>>>>>
>>>>>>> The API to this SDK calls for an 8 bit char string to pass to it, 
>>>>>>> but it doesn't like what I do.
>>>>>>>
>>>>>>> Any help on my conversion above?
>>>>>>>
>>>>>>> Thanks!
>>>>>>> jt
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
> 


0
7/14/2005 5:21:19 PM
Hi and see below...

"jt" <jtsoft@hotmail.com> wrote in message
news:qEYAe.152334$VH2.133160@tornado.tampabay.rr.com...
> Sorry, but your T2A(Did not work). Would not compile.
>
> I had to do this: strcpy(cPAGER_CODE, T2A((char *) (LPCSTR) cs));
>
> That compiled.
>
> So with my original code I posted it was doing the same thing I am doing
> now:
>     strcpy(cPAGER_CODE, T2A((char *) (LPCSTR) cs));

It is incorrect to cast from LPCSTR to char *, at least in the case the cs
is of type wchar_t.
The correct code look like:

USES_CONVERSION;
,,,,,,,
strcpy(cPAGER_CODE, T2CA(cs));

Also, search MSDN for USES_CONVERSION and/or "String Conversion Macros"

Regards,
Victor


0
7/14/2005 8:15:42 PM
Reply:

Similar Artilces:

SUMIFS help
Hi. Hope you’re able to help. I’m having difficulties the SUMIFS function. Either I’m using it incorrectly or perhaps it’s the wrong function for me! I’m trying to total the money amounts in column E as long as conditions in columns A (cell A6 in this example) and column H are True. However, I’m finding that the function is not totalling up the money amounts it should be totalling in column E. Instead, it’s just returning a single money amount in column E and ignoring the rest! This is the function as I’ve written it: =SUMIFS(BnkChqs!E3:E1000,BnkChqs!A3:A1000, A6,BnkChqs!...

newbie needs help
Hello, First to let you all know, I am a big novice at this kind of stuff, so please bear with me. What I am trying to do is make a trendchart with 9 different plots on it. How do I change the numbers on the side and bottom of the chart to read what I need them to? I take these tests 3 times a week and would like to chart all of them seperately and also together to chart progress for a whole month. One for each day, and then one for the month. Then I would like to do the same for the following months of the year. And I would like to have one chart to show the progress for the whole...

When converting MDE
Hello, Assuming most people aready have Office 2000, so I want to create an MDE . I understand we should use Access 2000 to make MDE. Since I do have Access 2002 or Office XP, how can I make MDE ver.2000 The other question, suppose I have Access 2000 and I successfully made MDE ver200, can this MDE be opened by Acess 2002 and higher? Thanks -- H. Frank Situmorang You must have Access 2000 to create an Access 2000 MDE. Yes: an Access 2000 MDE can be used in all later versions. -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/ti...

How can I convert text to all lowercase?
How can I convert text to all lowercase? I know that I can use the Format menu to convert a block of text to all uppercase, but is there any way to convert it to lowercase? If not with Excel, how about Word, DOS, any other way. I'm using Excel 7.0 (Office 95). Thanks in advance! Take a look at David McRitchie's Lower() Macro (I believe it will work in XL7): http://www.mvps.org/dmcritchie/excel/proper.htm#lower In article <20031207155812.23043.00000330@mb-m27.aol.com>, hbyardsale@aol.comnetorg (HBYardSale) wrote: > How can I convert text to all lowercase? > &g...

Help! Unable to mount public folder store event 9519
Hi, I am getting the following error when tring to mount the public folder store. Event Type: Error Event Source: MSExchangeIS Event Category: General Event ID: 9519 Date: 11/01/2006 Time: 00:10:26 User: N/A Computer: SERVER Description: Error 0x8004010f starting database "First Storage Group\f7967383-856a-4b7f-9023-37c269a0e908" on the Microsoft Exchange Information Store. Look up of DB Info failed. For more information, click http://www.microsoft.com/contentredirect.asp. I have tried numerous ms kb articles to no avail. I did find this on a news group :- -------------...

Formula help/suggestions?
I'm looking for help some help with a formula. How would I go about a formula for automatically adding 8 hours to a number each calendar month? I would like to open it and have it done for me if that's possible rather than having to remember to add it each month or forgetting if I did or not. For instance, i start out with the # 248 in a cell that I would like to automatically add 8 to each calendar month. "Gadgetman" <stoojz3@yahoo.com> wrote in message news:stoojz3-96EE83.15151022012011@usenet.ptd.net... > I'm looking for help some help with a formula....

Converting decimals to Time
Hi folks, For thousands of rows, time has been entered as 10.15 or 9.30. These are correct times, as in quarter-past-ten and nine thirty. To perform calculations, I obviously need to have a : (semi-colon) not a . (full-stop) Find and replace won't work because 9.3 (nine thirty) comes up as 9:03. I can write a macro, but trying to avoid since it's for someone else. Any ideas? TIA, Piers Hi Piers, =TIME(INT(A1),MOD(A1,1)*100,0) -- Kind regards, Niek Otten Microsoft MVP - Excel "Piers 2k" <fake@msn.com> wrote in message news:uTDz539DHHA.1748@TK2MSFTNGP02.p...

need document properties statistics revision information
using excel 2000 pro in document properties; statistics tab; bottom half of info i do see "last saved by" info but cannot find help on how to get the "revision number" and "total editing time" information.. can anyone help me with this.. I would like to set it up so that it is automatically entered for every document i create and not have to recreate for every file.. thanks ...

I need help with a formula
Hi everyone I'm making a stock list sheet and I like to put on it the value - and + .. like when I take boxes out it will give me the total and when I add in it will change also. This is for a weekly count. I'm very new to excel so please H-E-L-P-. I need the instruction like u give it to a child. :) :) Thanks a lot -- pampam ------------------------------------------------------------------------ pampam's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=26224 View this thread: http://www.excelforum.com/showthread.php?threadid=395241 We need ...

formula help 02-10-10
Hi- Issue: 211 310 410 569 Would like to accomplish: 2211 2310 2410 2569 How do I add number 2 infront of the above ISSUE numbers as I have thousands of line to do. Soth If your number is in column A then in column B type =2 & A1 and copy it down. -- -John http://www.jmbundy.blogspot.com/ Please rate when your question is answered to help us and others know what is helpful. "Soth" wrote: > Hi- > > Issue: > 211 > 310 > 410 > 569 > > Would like to accomplish: > 2211 > 2310 > 2410 > 2...

Thunking a 32-bit HANDLE to a 64-bit HANDLE
Currently I am converting a 32-bit WDM driver to a 64-bit KMDF driver that will continue to work with our 32-bit DLL and our customer's 32-bit applications. The sample code for thunking 32-bit items shows the following Buffer->Handle = (HANDLE)Buffer32->Handle; see: http://msdn.microsoft.com/en-us/library/aa489604.aspx Buffer32->Handle is declared as UINT32 Handle The driver compiler issues error number C4312 for this cast. The code that I have adopted (to get it to compile) is: handlerInputs.hEvent = (HANDLE) (ULONG_PTR) p_handlerInputs3...

Convert Publisher letterhead to Word
How do I convert my letterhead creaded in Publisher to Word or other word processing software, e.g., OpenOffice, so that I may create text in the letterhead to email to clients/customers? You may reply privately to tannj2@comcast.net if you wish. Thank you. Joe Right-click the creation, save as picture. This tutorial is perfect for what you want to do http://sbarnhill.mvps.org/WordFAQs/Letterhead.htm -- Mary Sauer http://msauer.mvps.org/ "JoOffice" <JoOffice@discussions.microsoft.com> wrote in message news:BD4E5467-4F84-44B1-A46D-69C470B6B0AF@microsoft.com... > How ...

can't convert jpg or other into publisher
I reinstalled publisher after reformatting my xp Dell. Now publisher will not convert image into the page where I want a picture. I can scan one in, but can't import clip art or a picture located elsewhere. I can import a picture into word. I reinstalled publisher again and same thing. I put it on a friends computer and everything works fine - I'm puzzled. What are they referring to when it's saying can't convert the image - also mentions a graphic filter?? I need help. Jeanne Importing from where? Are you using the Clip Gallery or Organizer? If you are trying to import ...

Excel and Calendar Control 8.0
Enter an Excel worksheet. Click Insert, select Object and then, Calendar Control 8.0. Now, the Calendar is shown on the worksheet. And then, the worksheet operations is finished with the Calendar. Please say, how to remove the Calendar from the worksheet. Regards. ...

sql replication on GP 8.0
Hello, I was wondering if it is possible to setup replication on the Great Plains db's ie Dynamics and the company databases? If so which replication method does anyone suggest? Thanks in advance. Jake Jake- I have tried this before, and I don't think it's possible. The replication adds a column to every table (I forgot the name, but something like Replication ID). This messes with the stored procs that dexterity uses to read the tables. Regards, Brenner bklenzman@klenzmanconsulting.com "Jake" wrote: > Hello, > > I was wondering if it is...

Need Exchange limit help
I have a new SBS 2008 Server setup in a manufacturing environment. Two users within the company send and receive large CAD files. How do I allow this process? Right now one user is try to send a 185MB file and it is saying "the message being sent exceeds the message size established for this user." I have tried setting the limit in the console to 10GB and now I have unchecked the "enforce the mailbox quotas" box and he still can't send. If I go into the Exchange Management Console I still don't see how I can make this work. Is this something that...

Combining 2 Text Strings in Body of E-Mail Q
I am trying to create a string of text to place in the message body of an e-mail. Using Ron De Bruins code I've run in to the "Too many line continuations". I've a requirement for 31 lines, but it hits this error on line 24. How can I combine 2 text strings to appear in the message body of the reports. My code with only the first stringbody is:- Sub Mail_New_Version() Dim FileExtStr As String Dim FileFormatNum As Long Dim Sourcewb As Workbook Dim Destwb As Workbook Dim TempFilePath As String Dim TempFileName As String Dim OutApp As O...

How to Insert brackets within string
In my worksheet, I have two columns, Col A for users to enter projects numbers while Col B for work description and Col C for cost spent. The project numbers and cost are then collected into pivot table in another workbook for other calculation. The problem now is some of the project numbers are like this 1100, 1100(A), 1307(E), 1611(A), 1611(B), 1612(C), 1612(D), 10303(1) and etc. So, if the users enter 1100A instead of 1100(A), then I cannot do the caluculation correctly. If the user enter 1100A mistakenly, Can we do some code to change it to 1100(A) ? using IF-else maybe or ?? Please ad...

Convert Word Table -> Excel without merged cells?
Whenver I copy/paste tables from word to excel, I get merged cells in Excel whenever there are line breaks in the word table cells. How can I avoid this? TIA Steve Saved from a previous post: If your cells in your word table contain paragraph mark or linebreak characters, then excel will bring them over as separate cells. One way around it is to convert those paragraph marks & linebreaks to unique characters, then copy|paste and then convert them back to linefeeds. I like this technique (inside a copy of the word file): Select your table. Edit|replace|Special (show More if required)...

Converting an Excel List into Access
I am unable to import a specific excel document into Access. I have done countless other imports and never encountered an error. What are some possible reasons for being unable to import the file? Yes all that shows up is: "An error occured while trying to import(directory path here). The file was not imported" >-----Original Message----- >What happens when you try to import it? Is there an error message? > >Dano wrote: >> I am unable to import a specific excel document into >> Access. I have done countless other imports and never >> encountered...

Help with Hurricane Database
I work at the Corporate office of a fast food chain. We have almost 1000 stores in 10 states - mostly in the South. We have many stores in the hurricane zones. During Rita and Katrina we decided we needed a better way to track how our stores are affected and what help we could provide. I've designed a database to do this. I have three main tables: tblHurricane Info: fldHurricaneYear fldHurricaneName tblUnitInfo: fldUnit - the unit number assigned to the store fldAddress fldCity fldState fldZip fldPhone fldDO fldMgr tblUnitForm fldAutoNumber fldUnit fldHurricaneName fldPr...

Converting 97 Outlook Notes to Outlook 2003
Help! Where have our notes gone? We've just converted from Outlook 97 to Outlook 2003 and all of our notes disappeared. Where did they go and how do I get them to convert to 2003?? Thanks! ...

converting firgures in words and vice versa
if i have stored a figure in one and in other cell i want to get that figure in words is it possible if yes then how as well as vice versa. Look here for one way traffic: http://xldynamic.com/source/xld.xlFAQ0004.html I've never seen it the other way around -- Kind regards, Niek Otten Microsoft MVP - Excel "nitesh" <nitesh@discussions.microsoft.com> wrote in message news:88B02773-0F9F-4963-A284-F75D48A9DAE7@microsoft.com... | if i have stored a figure in one and in other cell i want to get that figure | in words is it possible if yes then how as well as vice versa. ...

Outlook Certification Help
Do you need additional proof that you are an Outlook genius? Would you enjoy the respect and additional income that could come from being able to help everyone in your office on Microsoft Outlook? Get your Outlook Specialist certification and realize the benefits it can have. "Are You Certifiable (In Outlook, At Least)" is available at http://www.linkemup.us/areyoucertifiable.htm for only $18. It will go through each subject on the test and help you to prepare for this certification. If you do not plan to get certified but need a little extra help on using Outlook it is an excell...

32 bit and 64 bit question
Will the 2007 Office for Homes run on both 32 bit and 64 bit processors? yes "bernie" <bernie@discussions.microsoft.com> wrote in message news:24407929-DA37-4056-8B72-782512C2513F@microsoft.com... > Will the 2007 Office for Homes run on both 32 bit and 64 bit processors? ...