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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Voigt [C++ MVP]

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

    Chip Gore wrote:
    On Apr 10, 4:54 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
    wrote:
    >On Thu, 10 Apr 2008 14:41:19 -0700, Chip Gore
    ><chip.g...@int ersystems.comwr ote:
    >>
    >>[...]
    >>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()
    >>method.
    >>
    >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
    >byte).
    >>
    >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
    >point:http://msdn2.microsoft.com/en-us/library/bb384865.aspx
    >>
    >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.publ ic.dotnet.frame work.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.
    >>
    >Pete
    >
    Thanks for the feedback, I'll re-post the request in the interop
    newsgroup
    Actually, because you are using the C++/CLI compiler,
    microsoft.publi c.dotnet.langua ges.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 PtrToStringChar s function.


Working...