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.