473,407 Members | 2,359 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,407 software developers and data experts.

Parameter Passing from C# to C++

I need to build a managed DLL in C++ and call it from C#. I need this
to work with remoting as well.

In C#, class objects are reference types, so if an object is passed
directly to a C++ method it is considered a reference to the object.
C# call:
i = some_method( some_object );
C++ method:
int some_method( some_class ^ some_object)
{
int result;
some_object->member1 = 123;
result = some_object->member2 * 2;
return result;
}
This is fine until we need to run with remoting. For C# to marshal the

class object in both directions (so the function can change members of
the object and pass the new value back), then in C# we must use a "ref"

call:
i = some_method( ref some_object );
How should the C++ method be written to accept this call?
Thanks - any suggestions are appreciated.

Jan 11 '07 #1
2 1305

"Rich" <ri************@us.army.milwrote in message
news:11**********************@p59g2000hsd.googlegr oups.com...
>I need to build a managed DLL in C++ and call it from C#. I need this
to work with remoting as well.

In C#, class objects are reference types, so if an object is passed
directly to a C++ method it is considered a reference to the object.
C# call:
i = some_method( some_object );
C++ method:
int some_method( some_class ^ some_object)
{
int result;
some_object->member1 = 123;
result = some_object->member2 * 2;
return result;
}
This is fine until we need to run with remoting. For C# to marshal the

class object in both directions (so the function can change members of
the object and pass the new value back), then in C# we must use a "ref"

call:
i = some_method( ref some_object );
How should the C++ method be written to accept this call?
int some_method( some_class^% some_object);

But I think you should be using InAttribute and OutAttribute to tell
remoting whether to copy the object before and after. Haven't used remoting
before though, only interop, so this is just a wild guess.
>

Thanks - any suggestions are appreciated.

Jan 11 '07 #2

The "^%" approach works great - thanks!

Jan 11 '07 #3

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

Similar topics

3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
6
by: Brian Ross | last post by:
Hi, I am trying to do something similar to the following: int Func1(int x, int y); double Func2(double x, double y); template <typename FuncT> // <- What would go here class CObjectT {
4
by: Ron Rohrssen | last post by:
I want to show a dialog and when the form (dialog) is closed, return to the calling form. The calling form should then be able to pass the child form to another object with the form as a...
6
by: wiredless | last post by:
What is the advantage of passing an interface type? according to UML (visio) when i reverse engineer existing code to a UML diagram I get the error "UMLE00046: sample : - An interface cannot...
21
by: vmsgman | last post by:
Here is a code sample ... int blah = ReadFile( defArray, defFileName, w, h); // Read File Contents into memory array and return for processing public int ReadFile( ref ushort nArray, string...
20
by: Brien King | last post by:
If I have a parameter that has an Object type (as opposed to something like a string), can I make that parameter a CONST? Right now, if you pass an object into a sub/function, that sub/function...
4
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and the goal is to pass the "catID" from default.aspx...
8
by: =?Utf-8?B?UmF2aQ==?= | last post by:
Hi, I'm trying to pass values of different data-types to a web-service. I thought it would be easier to box these values and pass them as a System.object parameter, like public void...
16
by: Theo R. | last post by:
Hi all, Does the C99 Standard explicitly mention the need for a stack for passing arguments or Is this platform specific? As an example, the ARM9 processor recommends Core Registers R0-R3 be...
4
by: =?Utf-8?B?QmlsbEF0V29yaw==?= | last post by:
Hi, We recently converted a 1.1 project to 2.0 and this included a webservice which accepted XML for one of the parameters. Since converting to 2.0 I am getting the following message: --- A...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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,...
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,...
0
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...
0
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...
0
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,...
0
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...

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.