473,386 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

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.
Nov 17 '05 #1
1 4646
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.
Nov 17 '05 #2

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

Similar topics

0
by: Ed Richter via .NET 247 | last post by:
Hi all, Simple question concerning infopath, webservice, and an INSERTINTO Sql command: WARNING: All following content is NEWBIE generated and froughtwith errors (probably) All I want to do...
2
by: Rookie | last post by:
Hi, I had a question on DllImport. On importing a function from a VC++ dll using DllImport (to a C# program), the function argument data types and the return types may be of a type that is not...
0
by: Paul Cotgrove | last post by:
I am currently in the process of wrapping the SNMP API provided by MS to provide a managed assembly that can be referenced within my C# services for performing SETs, GETs, etc. I have hit a snag...
2
by: Howard Kaikow | last post by:
I've got the following in a VB 6 project: Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long...
0
by: swartzbill2000 | last post by:
I am familiar with the VB6/VC6/ATL way of marshalling an incoming interface via New (VB), and then marshalling an outgoing interface with some form of Advise. To me it looks like .Net has...
2
by: bonk | last post by:
I am currently trying to write a longer article about Marshalling when using . Does anyone know books, articles, or websites that cover Marshalling in Platform Invocation Services ()?
2
by: RJ Lohan | last post by:
Howdy, I have a legacy DLL for which I have a problem marshalling a parameter type of char**. The function header (C++) is as so; extern "C" __declspec(dllexport) int __stdcall...
5
by: PickwickBob3 | last post by:
I am trying to obtain a list of HID devices and am trying to use UINT GetRawInputDeviceList( PRAWINPUTDEVICELIST pRawInputDeviceList, PUINT puiNumDevices, UINT cbSize); a USER32.dll. but...
11
by: itdevries | last post by:
Hi, I'm trying to convert some char data I read from a binary file (using ifstream) to a float type. I've managed to convert the int types but now I need to do the float types as well but it...
2
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.