Vb到C#DLL库的问题 [英] Vb to C# DLL library problem
问题描述
你好。
从一段时间以来,我试图解决这个问题而没有任何成功。
任何帮助都将不胜感激。
我有外部库DLL,需要的方法对输入进行一些计算并给我输出(我没有访问代码)
------ ------------------------------------------------ <无线电通信/>
调用此库的工作excel VB脚本是
Hello.
From some time I try to solve this problem without any success.
Any help would be greatly appreciated.
I have external library DLL with needed methods to do some calculation on inputs and gives me the output (I don't have acces to code)
------------------------------------------------------
The working excel VB script to call this library is
Dim Inputs() As Double
Dim Outputs() As Variant
ReDim Inputs(1 To 1, 1 To NbrInputs&)
For i& = 1 To NbrInputs&
Inputs(1, i&) = CDbl(InRange(i&).Value)
Next i&
ABC.CalculateMatrix(Inputs#, Outputs)
-------------------------------- ----------
我在使用C#连接库时遇到很大问题
该方法应该在C#
ABC.CalculateMatrix(ref System.Array,ref System.Array)
输入和输出数组似乎不起作用。我已经尝试了几乎所有的东西
我尝试了什么:
------------------------------------------
I have great problem interfacing the library with C#
the method should be in C#
ABC.CalculateMatrix(ref System.Array, ref System.Array)
The input and output arrays do not seem to work.I've tried nearly everything
What I have tried:
Double[] Inputs = new Double[4];
Object[] Outputs = new Object[1];
ABC.CalculateMatrix(Inputs, Outputs);
我得到的错误是
System.Runtime.InteropServices .COMException'
对象变量或未设置块变量
推荐答案
ReDim Inputs(1 To 1, 1 To NbrInputs&)
那个创建一个具有非零下限的二维数组。要在C#中复制它,您需要:
That creates a two-dimensional array with a non-zero lower bound. To duplicate that in C#, you would need:
Array Inputs = Array.CreateInstance(
typeof(double),
new[] { 1, NbrInputs }, // lengths
new[] { 1, 1 }); // lower bounds
for (int i = 1; i <= NbrInputs; i++)
{
double value = Convert.ToDouble(InRange[i].Value);
// NB: Can't use indexer to set the value for a non-zero lower bound:
Inputs.SetValue(value, 1, i);
}
从您发布的代码中不清楚需要传递给输出的内容
参数。您需要查看第三方代码的文档,看看是否能为您提供任何线索。
It's not clear from the code you've posted what needs to be passed to the Outputs
parameter. You would need to check the documentation of the third-party code to see if that gives you any clues.
ABC.CalculateMatrix需要参考:
ABC.CalculateMatrix expects references:
System.Array Inputs = Array.CreateInstance(typeof(Double), 4);
System.Array Outputs = Array.CreateInstance(typeof(Object), 1);
ABC.CalculateMatrix(ref Inputs, ref Outputs);
这篇关于Vb到C#DLL库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!