PC Review


Reply
Thread Tools Rate Thread

Data marshalling in C++/CLI <-> C++

 
 
Guest
Posts: n/a
 
      18th Feb 2004
Hi,

Is there any good links for datatype interop?

I need to pass some structure pointers into an unmanaged method and return
char* etc but having some problems in my C++/CLI proxy class.

I have a methods with signitures like the following...

unsigned char someMethod(unsigned char blah, SOMESTRUCT* somestruct);
what I did in the proxy class was...
System::Byte someMthod(System::Byte blah, SomeStruct* someStruct);

and..

char* someMethod2(unsigned char something);
what I did in the proxy class was...
System::String someMethod2(System::Byte something);

Am I anywhere near right or totally wrong on the types, The char* <->
System::String is wrong and the SOMESTRUCT* etc is giving me problems (the
SOMESTRUCT also has some bitfields in there, do I setup a seperate struct
and attribute it as [Flags] in the usual powers of 2? and what about unions?
I have to set the structs as Sequential layout right?).


Thanks.


 
Reply With Quote
 
 
 
 
Brandon Bray [MSFT]
Guest
Posts: n/a
 
      18th Feb 2004
Good afternoon!

First, to reduce confusion, let me set the correct terminology. C++/CLI is
only the name of the committee that is creating the language binding between
C++ and CLI. The language is still C++, so saying anything like going
between C++ and C++/CLI is closer to sending messengers between two
committees and nothing about interoperating between two languages (because
its just one language).

.. wrote:
> Hi,
>
> Is there any good links for datatype interop?


The Whidbey version of Visual C++ will include a marshalling library
tailored to C++. It should make interop between two worlds of data much
easier.

> I need to pass some structure pointers into an unmanaged method and
> return char* etc but having some problems in my C++/CLI proxy class.
>
> I have a methods with signitures like the following...
>
> unsigned char someMethod(unsigned char blah, SOMESTRUCT* somestruct);
> what I did in the proxy class was...
> System::Byte someMthod(System::Byte blah, SomeStruct* someStruct);
>
> and..
>
> char* someMethod2(unsigned char something);
> what I did in the proxy class was...
> System::String someMethod2(System::Byte something);


Changing char to System::Byte doesn't affect very much. When you compile the
program, you'll see the compiler thinks of System::Byte as unsigned char.
The only difference between the two is when you form a pointer to them.
(BTW, this is in the old version of the syntax; the new version doesn't have
these rules for pointers.)

char * ==> unsigned char *
System::Byte * ==> unsigned char __gc *

The __gc * in this case is known as an interior pointer. The other one is
just a normal pointer. A pointer can add __gc automatically, but it cannot
be removed as easily. To remove a __gc from a pointer, a __pin pointer must
be used.

> Am I anywhere near right or totally wrong on the types, The char* <->
> System::String is wrong and the SOMESTRUCT* etc is giving me problems (the
> SOMESTRUCT also has some bitfields in there, do I setup a seperate struct
> and attribute it as [Flags] in the usual powers of 2? and what about
> unions? I have to set the structs as Sequential layout right?).


If you're doing all of this in C++, there's no point in creating extra types
to represent unions and more enums. Thus, Sequential layout really isn't
necessary in C++. (There are a few cases where it could be useful, but if
you're just getting started with doing .NET and C++, I'd leave that option
alone until you have more experience.)

For turing a System::String into a char*, there are a lot of posts about
that in the current newsgroup, so I would start by doing a search.

I hope that helps!

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Marshalling Data Question =?Utf-8?B?UGlja3dpY2tCb2Iz?= Microsoft Dot NET 5 13th Jun 2006 03:48 PM
DllImport and Data Marshalling Rookie Microsoft C# .NET 2 6th Jul 2004 08:18 PM
Data marshalling in C++/CLI <-> C++ Microsoft VC .NET 1 18th Feb 2004 10:47 PM
Data marshalling in C++/CLI <-> C++ Microsoft Dot NET Framework 1 18th Feb 2004 10:47 PM
Marshalling Data Types Paul Cotgrove Microsoft VC .NET 0 26th Nov 2003 04:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:36 AM.