在Vb.net 2010中调用C ++ DLL函数

编程入门 行业动态 更新时间:2024-10-28 10:22:11
本文介绍了在Vb 2010中调用C ++ DLL函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

double __ stdcall Dif( int a) { if (a!= 1300 ) { return value ; } else { return 9048034884 ; } }

这是我在C ++中的功能。 我想要从VB 2010调用此dll函数。 请帮助我这样做。

解决方案

Imports System.Runtime.InteropServices Public Class Form1 < DllImport( Dlllock.dll , CallingConvention:= CallingConvention.StdCall)> _ 私有共享函数Dif(< MarshalAs(UnmanagedType.I4)> ByVal b As Integer)As Double 结束函数

昏暗 a As Double a = Dif( 1300 ) MsgBox(a)

你需要的是P / Invoke: en.wikipedia/wiki/Platform_Invocation_Services [ ^ ]。 你真的需要学习如何使用它。请从这里开始: msdn.microsoft/library/en-us/ vcmxspec / html /vcmg_PlatformInvocationServices.asp [ ^ ]。 此CodeProject文章也很有用: Essential P / Invoke [ ^ ]。 祝你好运,
-SA

double __stdcall Dif(int a) { if (a != 1300) { return value; }else { return 9048034884; } }

This is my function in C++. I want to call this dll function from VB 2010. Please Help Me to do this.

解决方案

Imports System.Runtime.InteropServices Public Class Form1 <DllImport("Dlllock.dll", CallingConvention:=CallingConvention.StdCall)> _ Private Shared Function Dif(<MarshalAs(UnmanagedType.I4)> ByVal b As Integer) As Double End Function

Dim a As Double a = Dif(1300) MsgBox(a)

What you need is called P/Invoke: en.wikipedia/wiki/Platform_Invocation_Services[^]. You really need to learn how to use it. Please start here: msdn.microsoft/library/en-us/vcmxspec/html/vcmg_PlatformInvocationServices.asp[^]. This CodeProject article can also be useful: Essential P/Invoke[^]. Good luck,
—SA

更多推荐

在Vb.net 2010中调用C ++ DLL函数

本文发布于:2023-11-08 02:25:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568075.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   net   Vb   DLL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!