473,782 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.
Jun 27 '08 #1
0 1395

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

Similar topics

16
2158
by: cppaddict | last post by:
I thought that: char x; made x into a pointer-to-char. But how come the following code won't compile: int main() { char pbuf;
7
2575
by: Ollej Reemt | last post by:
Hello, I would like to know if there is a difference in c++ between the following two method-declarations: void Method(); and void Method(void);
3
14582
by: Dennis | last post by:
Excuse me!! I have a DLL file named "TESTDLL.DLL". In TESTDLL.DLL export function : void GetPChar(char** pstr); In .NET C# , How to call "GetPChar(char** pstr)" function ?
1
1641
by: halise | last post by:
hello, i am trying to wrap an unmanaged C++ code to managed one so that i can use it within c#, and i am using IJW - "It Just Works" - method for that. In the code, there is a function which takes a "filename" as one of its arguments and the type of that is "char*". In the documents of msdn, "char*" is mapped to String or StringBuilder by marshaller. although i searched in the goggle, i couldnt find any kinds of simple-because I am not...
26
11753
by: =?gb2312?B?wNbA1rTzzOzKpg==?= | last post by:
i wrote: ----------------------------------------------------------------------- ---------------------------------------- unsigned char * p = reinterpret_cast<unsigned char *>("abcdg"); sizeof(reinterpret_cast<const char *>(p)); ----------------------------------------------------------------------- ---------------------------------------- the compiler tells me that "reinterpret_cast from type "const char * " to type "unsigned char *"...
4
3294
by: =?utf-8?B?Qm9yaXMgRHXFoWVr?= | last post by:
Hello, what is the use-case of parameter "start" in string's "endswith" method? Consider the following minimal example: a = "testing" suffix="ing" a.endswith(suffix, 2) Significance of "end" is obvious. But not so for "start".
4
8437
by: Virtual_X | last post by:
some function make the data type of it's parameters as "const char*" why not use char or char* instead what would be different
14
307
by: Anna | last post by:
I try to put 8 int bit for example 10100010 into one character of type char(1 octet) with no hope . Could anyone propose a simple way to do it? Thank you very much.
13
7966
by: xzzy | last post by:
None of the following properly do the VB.net double quote conversion because all of the following in csharp convert to \" instead of just a double quote: " I have tried: char myDoubleQuote = (char)34; string myDoubleQuote = "" + (char)34;
0
9639
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...
0
10311
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
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
8967
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...
0
5378
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
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4043
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
3
2874
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.