469,282 Members | 2,075 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

System::String to LPCSTR?

How do i call from managed C++ function wich accepts LPCSTR?

void AddName( System::String *sName )
{
AddName( (LPCSTR) sName )); -- does not compile.
}
George.
Nov 16 '05 #1
3 14178
George Ter-Saakov wrote:
How do i call from managed C++ function wich accepts LPCSTR?


LPCSTR is ANSI =>

See: StringToHGlobalAnsi (System::Runtime::InteropServices::Marshal)
http://msdn.microsoft.com/library/en-
us/cpref/html/frlrfsystemruntimeinteropservicesmarshalclassstrin gtohglobala
nsitopic.asp

But conversion to ANSI is bad... because String is UNICODE... so if it
contains some unicode characters this might be lost.

Better convert to unicde: StringToHGlobalUni
or use PtrToStringChars (which is faster; if you do not need to modify the
string)

See also:
HOW TO: Convert from System::String* to Char* in Visual C++ .NET
http://support.microsoft.com/?kbid=311259

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/useritems/leakfinder.asp
Nov 16 '05 #2
Let me rephrase.

I have a __gc class with method AddName(String sName). This class is a
wrapper for regular C++ class with method AddName(LPCSTR sName)

How do i transfer call from AddName (String ) to p->AddName(LPCSTR)?
void AddName( System::String *sName )
{
p->AddName( (LPCSTR) sName )); -- does not compile.
}

Thanks.
George.

"George Ter-Saakov" <we@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
How do i call from managed C++ function wich accepts LPCSTR?

void AddName( System::String *sName )
{
AddName( (LPCSTR) sName )); -- does not compile.
}
George.

Nov 16 '05 #3

Great.

thanks.

George.

"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn*********************************@207.46.24 8.16...
George Ter-Saakov wrote:
How do i call from managed C++ function wich accepts LPCSTR?
LPCSTR is ANSI =>

See: StringToHGlobalAnsi (System::Runtime::InteropServices::Marshal)
http://msdn.microsoft.com/library/en-

us/cpref/html/frlrfsystemruntimeinteropservicesmarshalclassstrin gtohglobala nsitopic.asp

But conversion to ANSI is bad... because String is UNICODE... so if it
contains some unicode characters this might be lost.

Better convert to unicde: StringToHGlobalUni
or use PtrToStringChars (which is faster; if you do not need to modify the
string)

See also:
HOW TO: Convert from System::String* to Char* in Visual C++ .NET
http://support.microsoft.com/?kbid=311259

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/useritems/leakfinder.asp

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Yifan | last post: by
8 posts views Thread by Ioannis Vranos | last post: by
24 posts views Thread by Marcus Kwok | last post: by
2 posts views Thread by Alejandro Aleman | last post: by
4 posts views Thread by John Smith | last post: by
14 posts views Thread by =?Utf-8?B?Sm9hY2hpbQ==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.