从Visual Basic .NET传递双指针到C DLL [英] Passing double pointer to C DLL from Visual Basic .NET

查看:79
本文介绍了从Visual Basic .NET传递双指针到C DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有双指针作为参数的C函数。我构建了一个DLL文件,并希望在我的Visual Basic项目中使用它。我不知道如何处理双指针。我的代码是错的吗?


这是我的示例代码。


我的C文件(该函数更新了值,它是一个101元素的双数组。):

 void myFunction(double * out)

我的头文件:

 extern" C" __declspec(dllexport)void myFunction(double *); 

我的VB文件(DLL导入):


< pre class ="prettyprint lang-vb">< DllImport(" myDLL.dll",EntryPoint:=" myFunction",CallingConvention:= CallingConvention.Cdecl)>   
Private Sub myFunction(ByVal out As IntPtr)   
End Sub

我的VB文件(DLL调用):

 Dim out As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(GetType(Double))* 101)        

myFunction(out)        '运行我的DLL函数

Dim res As Double = Marshal.ReadIntPtr(out,100)'101th element





解决方案

最后一行似乎不正确。


使用Marshall.Copy(),我可以解决我的问题。


I have created a C function with a double pointer as an argument. I built a DLL file and want to use it in my Visual Basic project. I am not sure how to deal with the double pointer. Is my code wrong ?

Here is my sample code.

My C file (The function updates out values, it is an 101 elements double array.):

void myFunction(double* out)

My header file :

extern "C" __declspec(dllexport) void myFunction(double*);

My VB file(DLL Import) :

<DllImport("myDLL.dll", EntryPoint:="myFunction", CallingConvention:=CallingConvention.Cdecl)>    
Private Sub myFunction(ByVal out As IntPtr)    
End Sub

My VB file(DLL call):

Dim out As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(GetType(Double)) * 101)        

myFunction(out)        ' Run my DLL function

Dim res As Double = Marshal.ReadIntPtr(out, 100) '101th element


解决方案

The last line does not seem correct.

Using Marshall.Copy(), I could solve my problem.


这篇关于从Visual Basic .NET传递双指针到C DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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