473,503 Members | 3,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing structure from Managed C++ to C#,

4 New Member
Hi,

i am new bie to managed C++ , i have an C# DLL , which i need to invoke from managed C++ and pass a structure as a parameter , Can any one help me out on this issue...



Thanks in advance...
Jan 21 '08 #1
2 3769
weaknessforcats
9,208 Recognized Expert Moderator Expert
You will need to read the interoperability pages in MSDN.
Jan 21 '08 #2
sarvankr
4 New Member
Hi All,

I have found the solution for this problem , the simplest way of passing structure from Managed C++ to C# is ..



Eg:

In MC++

public struct xyz

{

public:

int x;

int y;

};



Method in MC++ invoking C# Method say

...............

..............

CsharpDLLNamespace::CSharpeClass^ ObjectofSharpMethod= gcnew CsharpDLLNamespace::CSharpeClass();



xyz obj;

obj.x = 10 ;

obj.y = 20 ;

ObjectofSharpMethod>CsharpMethod((System::IntPtr)& obj);



In C#



[StructLayout(LayoutKind.Sequential, Pack = 2)]

public class xyz

{

public int x;

public int y;

}



public void CsharpMethod(IntPtr pob )

{

xyz obj = new xyz();

Marshal.PtrToStructure(pob, obj);

Console.WriteLine("Converted Successfully" + "x : " + obj.x+ "y :" + obj.y);

}
Jan 23 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6559
by: Chris | last post by:
Hi, I seem to be having a problem I can't quite figure out. Currently, I have the following code (below). In the SendMsg function, I create a 'Qtkmsg' which converts the string 'text' into a...
2
2234
by: Gregory Khrapunovich | last post by:
Hi, I need to pass a structure between C++ DLL and C# client (both ways). Among other elements the strcuture must contain a fixed size array of integers. In C++ I can successfully declare a...
0
1683
by: nygiantswin2005 | last post by:
I would like to know how do I pass a pointer to a struct from managed code to unmanaged code. For example if I create structure like this in managed code. StructLayout( LayoutKind.Sequential,...
15
14818
by: John Alway | last post by:
Hello, I'm using a DLL I wrote in C++, and am attempting to call and use it from VB. This works fine for functions where I pass parameters by value, but I can't get pointers to work. I get...
22
25546
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
5
4380
by: renjini | last post by:
I am a starter in C# ... I will present my problem : I am wrapping a C dll in C#. The C dll exports a function which takes a structure MYSTRUCT holding 2 function pointers(callback functions)....
0
1842
by: ElysianEagle | last post by:
Hi, I have a DLL written in C that creates a structure as a local variable, populates it, and then calls a function in managed c#. here is what im talking about: //-----unmanged code's header...
2
5605
by: Subodh | last post by:
Hi All, I want to use a C++ API in a static lib that returns a linked List in C# I am planning to P/Invoke to perform the Interop, I would like to know which way will be better to interop a...
6
3873
by: Andy Baker | last post by:
I am attempting to write a .NET wrapper for a C++ DLL file, but am having problems with passing strings as parameters. How should I be writing my C# function call when the C header file is...
0
7261
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
7315
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...
1
6974
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...
0
7445
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
5559
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,...
1
4991
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...
0
4665
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...
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
721
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.