在Vb.net 2010中调用C ++ DLL函数 [英] Calling a C++ dll Function in Vb.net 2010

查看:289
本文介绍了在Vb.net 2010中调用C ++ DLL函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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





这是我在C ++中的功能。

我想要从VB.net 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: http://en.wikipedia.org/wiki/Platform_Invocation_Services [ ^ ]。



你真的需要学习如何使用它。请从这里开始: http://msdn.microsoft.com/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.net 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: http://en.wikipedia.org/wiki/Platform_Invocation_Services[^].

You really need to learn how to use it. Please start here: http://msdn.microsoft.com/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函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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