471,348 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Re: Why is a "char *" method parameter being projected as a "sbyte *"?

Chip Gore wrote:
On Apr 10, 4:54 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
>On Thu, 10 Apr 2008 14:41:19 -0700, Chip Gore
And when I try and call this from "C-Sharp-Land", I'm being told
that my s1 and s2 are of type "sbyte *", and I'm not sure how to
get a C# "string" to be able to be passed in to my DEMO::DoStuff()

Short, useless answer: in C#, the "char" type is Unicode, 2 bytes per
character. A C++ "char" is in fact the same as a C# "sbyte" (signed

What you really want to know is how to get .NET strings to play nice
with C++ strings ("char" arrays). Depending on what your C++ code
is doing, you either need to just use .NET strings (i.e. instances
of "String") in your managed C++ code, or you need to marshal
between the .NET String class and your C++ strings. Here's an MSDN
page that might be a good starting

In this newsgroup, Ben, Willy, and maybe one or two others, might
have an answer to your question. But this is a perfect example of
the sort of question that is completely on-topic in the
microsoft.public.dotnet.framework.interop newsgroup. In that forum,
they are doing this sort of thing on a regular basis and you'll get
the best, most complete answers posting in that newsgroup.


Thanks for the feedback, I'll re-post the request in the interop
Actually, because you are using the C++/CLI compiler,
microsoft.public.dotnet.languages.vc is the most appropriate place to
discuss this.

To be useful from C# and other .NET languages, the member functions of your
ref class should accept parameters of type System::String^. The C++/CLI
compiler provides some pretty simple methods for getting the data as native
C++ characters if you need to, for example the PtrToStringChars function.
Jun 27 '08 #1
0 1281

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by cppaddict | last post: by
7 posts views Thread by Ollej Reemt | last post: by
4 posts views Thread by =?utf-8?B?Qm9yaXMgRHXFoWVr?= | last post: by
4 posts views Thread by Virtual_X | last post: by

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.