我有一个正常的dll,导出了以下函数。将结构数组从c#传递给常规dll
extern "C" __declspec(dllexport) int FindNearestStuff(double _latitude, double _longitude , LocationStruct * locations[])
LocationStruct很简单
struct LocationStruct
{
long positionIndex;
long item;
};
我tryign使用从C#调用它
[DllImport("myclever.dll", CharSet = CharSet.None)]
private static extern int FindNearestStuff(double _latitude, double _longitude,
ref LocationStruct [] locations);
这一切都冷静和时髦的,我可以进入从DLL函数调试器。 在dll里LocationStruct数组填充正确,并且都非常好。
我的问题是,当它从DLL返回时,LocationStruct阵列是不回来的数据 - 只是空值...
我缺少什么?
结构LocationStruct \t \t { \t \t \t长roadIndex; \t \t \t long tdist; \t \t}; 和在c# 内部结构LocationStruct \t \t { \t \t \t公众诠释roadIndex; //它在C代码中的一长 \t \t \t public int tdist; //它的一个长C代码 \t \t}; – buzz 2009-11-19 03:00:50
我不认为P/Invoke可以在这里处理双重间接(通过C#端的'ref'传递数组,C++端指向指针)。你真的需要它吗? C++中不会有指向结构数组中第一个元素的指针吗? – 2009-11-19 03:16:48
我能想到的最简单的方法是使用不安全的C#。还要记住使用StructLayout.Sequential – 2009-11-19 03:34:57