.NET/COM Interop数组传递 [英] .NET/COM Interop array passing

查看:60
本文介绍了.NET/COM Interop数组传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将双精度数组从托管的.NET C#对象返回到非托管的c ++ COM代码?

如果在C#中,我将类定义为:(并告诉Visual Studio使程序集COM可见)

How do I return an array of doubles from a managed .NET C# object to unmanaged c++ COM code?

If in C# i define a class as: (and tell visual studio to make the assembly COM visible)

public interface _myinterface
{
    public double[] getDoubles()
}
public class myinterface: _myinterface
{
    public double[] getDoubles()
    {
        double[] doubles;
        doubles = new double[10];
        // set values here
        return doubles;
    }
}



我最后得到的类型库声明为:



I''m ending up with a type library declaration of:

SAFEARRAY(double) getDoubles();



当我在Visual Studio 2008中基于类型库创建C ++类时,我得到:



and when i create a C++ class in visual studio 2008 based on the type library i get:

SAFEARRAY * getDoubles()
{
    InvokeHelper(0x6002000a, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}



甚至不编译,因为它没有返回值.

我在这里尝试执行的操作是否有意义,并且/或者是否有其他方法可以产生更好的结果?

谢谢,
Barry



which doesn''t even compile because it is not returning a value.

Does what i''m attempting here make sense and/or is there a different way to do this that will yield better results?

Thanks,
Barry

推荐答案

在Com API和非托管代码中工作总是很棘手.下面的线程可能会帮助您.

http://www.codeproject.com/KB/cs/UnmanagedArraysInCSharp.aspx

问候
鲁西
working within Com API and unmanaged code is always tricky. Below thread might help you.

http://www.codeproject.com/KB/cs/UnmanagedArraysInCSharp.aspx

Regards
Rushi


这篇关于.NET/COM Interop数组传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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