473,725 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(unsi gned char blah, SOMESTRUCT* somestruct);
what I did in the proxy class was...
System::Byte someMthod(Syste m::Byte blah, SomeStruct* someStruct);

and..

char* someMethod2(uns igned char something);
what I did in the proxy class was...
System::String someMethod2(Sys tem::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 4680
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(unsi gned char blah, SOMESTRUCT* somestruct);
what I did in the proxy class was...
System::Byte someMthod(Syste m::Byte blah, SomeStruct* someStruct);

and..

char* someMethod2(uns igned char something);
what I did in the proxy class was...
System::String someMethod2(Sys tem::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
2733
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 is add a 4 column row to a SQL Server tableusing infopath, a webservice, and ADO.net. I've tried this: Public Function UpdateADMST(ByVal ID As String, ByVal PG AsString, ByVal LT As String, ByVal TX As String) As DataSet
2
5787
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 supported by C#. In this case if I am not mistaken the system performs default marshalling - matching the data types to its most similar equivalent in C#. Is this right? Also, I presume this can be overridden by using MarshalAs. Is this
0
1108
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 when it comes to marshalling between a managed type or structure and a variable binding list - namely the SNMPVarBindList that is required by a whole host of functions within the library. Has anyone out there got any idea how I do this or where...
2
5547
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 th32ParentProcessID As Long
0
1145
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 marshalling on a function-by-function basis. Is there a way in .Net to marshall entire interfaces? Bill
2
1421
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
2488
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 GetChildren(GetChildrenParm *, Results *);
5
2886
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 the function fails. Here is the code. I am new to Marshalling. Can anyone suggest my error and why? I am using C# with Visual Studio 2003 with 1.1 .NET Code: /*typedef struct tagRAWINPUTDEVICELIST { HANDLE hDevice; DWORD dwType;
11
3818
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 doesn't seem to work. The code below is what I'm trying to use. Anyone see any obvious errors? or have any hints/pointers? regards, Igor float floatRead = 0;
2
7205
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 Marshal.PtrToStructure to copy the all the data into the "other" array? unsafe public struct DeadReckoning {
0
8888
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...
1
9174
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
9111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8096
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...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4517
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
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2634
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.