如何从C DLL使用VB接收双精度数组 [英] How to receive an array of doubles using VB from a C DLL

查看:65
本文介绍了如何从C DLL使用VB接收双精度数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


这是我第一次在Compact Framework中遇到的问题。我现在使用完整的框架(v2.0)并且想知道是否有

,无论如何都没有在另一个DLL中构建单独的填充码。


这是外部C DLL函数的布局:


int thisFunction([in] double a,[in] int b,[out] ] double * c)


double * c参数传回6个双精度数组。


我的VB代码是这样的:


< DllImport(" External.DLL")_

公共共享函数thisFunction(ByVal a As Double,ByVal b As Integer,

ByRef c As Double())作为整数

结束功能

...

...

...

Dim iRet As Integer

Dim a As Double

Dim b As Integer

Dim c(5)As Double


a = 36.12

b = 4


iRet = thisFunction(a,b ,c)

....

....


目前,这个函数的调用离子正在崩溃。完整框架中针对此类问题的最佳解决方案是什么?


问候,

Neville Lang

解决方案

这是一个旧的C dll,还是一个较新的C ++ DLL?如果它已经老了,它可能使用了一个16位的int
,但你传递的是32位int。这可能是什么'b $ b使它崩溃,而不是一系列的双打。


T


Neville Lang写道:


>大家好,

这是我在Compact Framework中第一次遇到的问题。我现在正在使用完整的框架(v2.0)并想知道是否有
无论如何都没有在另一个DLL中构建单独的填充码。

这是外部C DLL函数的布局:

int thisFunction([in] double a,[in] int b,[out] double * c)

双* c参数传回6个双精度数组。

我的VB代码是这样的:

< DllImport(" External.DLL")_
公开共享函数thisFunction(ByVal a As Double,ByVal b As Integer,
ByRef c As Double())as Integer
结束函数
..
..
。 。
昏暗的iRet作为整数
Dim a As Double
Dim b As Integer
Dim c(5)As Double

a = 36.12 b = 4

iRet = thisFunction(a,b,c)
...
...

此刻,电话这个功能正在崩溃。在完整的框架上解决此类问题的最佳解决方案是什么?

问候,内维尔·朗


DLL正在使用32位INT,如果有任何帮助的话。


问候,

Neville Lang

坟墓 < to ** @ technetcenter.comwrote in message

news:hv *************** @ bignews5.bellsouth.net ...


这是旧的C dll,还是较新的C ++ dll?如果它已经老了,它可能使用了一个16位int的
,但是你传递的是32位int。这可能是什么'b $ b使它崩溃,而不是一系列的双打。


T


Neville Lang写道:


>>大家好,

这是我第一次在Compact Framework中遇到的问题。我现在正在使用完整的Framework(v2.0)并且想知道是否有关于这个问题的
而没有在另一个
DLL中构建单独的填充码。

int thisFunction([in] double a,[in] int b,[out] double * c)

> double * c参数传回一个6个双精度数组。

我的VB代码是这样的:

< DllImport(" External.DLL")_
公共共享函数thisFunction(ByVal a As Double,ByVal b As
Integer,ByRef c As Double())as Integer
结束函数
..
..
..
Dim iRet as Integer
Dim a As Double
Dim b As Integer
Dim c(5)As Double

a = 36.12
b = 4
iRet = thisFunction(a,b,c)
...
...

那一刻,对这个功能的调用正在崩溃。在完整的框架上解决此类问题的最佳解决方案是什么?

问候,内维尔·朗



Neville,


>< DllImport(" External.DLL")_ ByRef c As Double())As Integer



^^^^ ^


应该是ByVal

Mattias


-

Mattias Sj? gren [C#MVP] mattias @ mvps.org
http://www.msjogren .net / dotnet / | http://www.dotnetinterop.com

请回复到新闻组。


Hi all,

Here is a problem I first struck a while back in the Compact Framework. I am
now using the full Framework (v2.0) and wanted to know whether there is
anyway around this issue without building separate shim code in another DLL.

Here is the layout of the external C DLL function:

int thisFunction( [in] double a, [in] int b, [out] double* c)

The double* c argument passes back an array of 6 doubles.

My VB code is like this:

<DllImport("External.DLL")_
Public Shared Function thisFunction( ByVal a As Double, ByVal b As Integer,
ByRef c As Double() ) As Integer
End Function
...
...
...
Dim iRet As Integer
Dim a As Double
Dim b As Integer
Dim c(5) As Double

a = 36.12
b = 4

iRet = thisFunction( a, b, c )
....
....

At the moment, the call to this function is crashing. What is the best
solution for this type of problem on the full Framework?

Regards,
Neville Lang

解决方案

Is that an old C dll, or a newer C++ dll? If it''s old, it may be using
a 16 bit int, but you are passing it a 32 bit int. That may be what''s
making it crash, rather than the array of doubles.

T

Neville Lang wrote:

>Hi all,

Here is a problem I first struck a while back in the Compact Framework. I am
now using the full Framework (v2.0) and wanted to know whether there is
anyway around this issue without building separate shim code in another DLL.

Here is the layout of the external C DLL function:

int thisFunction( [in] double a, [in] int b, [out] double* c)

The double* c argument passes back an array of 6 doubles.

My VB code is like this:

<DllImport("External.DLL")_
Public Shared Function thisFunction( ByVal a As Double, ByVal b As Integer,
ByRef c As Double() ) As Integer
End Function
..
..
..
Dim iRet As Integer
Dim a As Double
Dim b As Integer
Dim c(5) As Double

a = 36.12
b = 4

iRet = thisFunction( a, b, c )
...
...

At the moment, the call to this function is crashing. What is the best
solution for this type of problem on the full Framework?

Regards,
Neville Lang


The DLL is using 32-bit INTs, if that is any help.

Regards,
Neville Lang

"tomb" <to**@technetcenter.comwrote in message
news:hv***************@bignews5.bellsouth.net...

Is that an old C dll, or a newer C++ dll? If it''s old, it may be using a
16 bit int, but you are passing it a 32 bit int. That may be what''s
making it crash, rather than the array of doubles.

T

Neville Lang wrote:

>>Hi all,

Here is a problem I first struck a while back in the Compact Framework. I
am now using the full Framework (v2.0) and wanted to know whether there is
anyway around this issue without building separate shim code in another
DLL.

Here is the layout of the external C DLL function:

int thisFunction( [in] double a, [in] int b, [out] double* c)

The double* c argument passes back an array of 6 doubles.

My VB code is like this:

<DllImport("External.DLL")_
Public Shared Function thisFunction( ByVal a As Double, ByVal b As
Integer, ByRef c As Double() ) As Integer
End Function
..
..
..
Dim iRet As Integer
Dim a As Double
Dim b As Integer
Dim c(5) As Double

a = 36.12
b = 4

iRet = thisFunction( a, b, c )
...
...

At the moment, the call to this function is crashing. What is the best
solution for this type of problem on the full Framework?

Regards,
Neville Lang



Neville,

><DllImport("External.DLL")_
Public Shared Function thisFunction( ByVal a As Double, ByVal b As Integer,
ByRef c As Double() ) As Integer

^^^^^

Should be ByVal
Mattias

--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


这篇关于如何从C DLL使用VB接收双精度数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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