将结构数组从C#传递给C ++ [英] Passing the structure array from C# to C++

查看:145
本文介绍了将结构数组从C#传递给C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我将结构数组从C#传递到(用c ++编写)com dll,

我传递的是ref a [1],数组包含多个值(a [2],a [3]包含数据),而我正在从com dll读取数据,如果我尝试读取[2],它只给出[1]数据它给了一些垃圾价值。





注意:我使用new运算符分配了内存((结构类型)[] a = new (结构类型)[5];)



Ex:int [] a = new int [5];





任何人都可以帮我解决如何将数据从C#传递到com dll。



我尝试过:



我尝试将其作为函数传递(a [1],selecteditem,0)



以上函数通过引用加载到c#中,对于该函数,我需要从c#传递数据。

Hi ,

I am Passing a structure array from C# to (written in c++)com dll,
I am passing as ref a[1], array contains multiple values(a[2],a[3] contains data), while i am reading the data from com dll its only giving a[1] data if i try to read a[2] it is giving some garbage value.


Note: i allocated the memory using new operator( (structure type) []a = new (structure type) [5];)

Ex: int []a = new int[5];


Can anyone help me how to pass data from C# to com dll.

What I have tried:

I have tried by passing it as function(a[1], selecteditem, 0)

Above function is com dll loaded into c# by reference, for that function i need to pass the data from c#.

推荐答案

主要问题是内存布局在不同的运行时,所以我的第一个和硬编码了一个dvice在这种结构中只使用原生值(int,double和char [])。你不能转移对象!!!

第二种是转移只读,这意味着每个运行时一个一个地复制值。



阅读我的文章了解此类界面并深入了解源代码。你没有提供足够的结构细节。
The primary problem is the memory layout in the different runtime, so my first and hard coded advice is to use only native values (int, double and char[]) in such structures. You cant transfer objects!!!
The second is to transfer read-only, that mean that each runtime copies the values one by one.

Read my article for such interfaces und dig into the source. You havent provided enough details of your structure.


请看这个博客

修改结构数组(默认封送) [ ^ ]



希望它有帮助。



-Praveen。
Please see this Blog
Modifying an array of structures (default marshaling)[^]

hope it helps.

-Praveen.


这篇关于将结构数组从C#传递给C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆