问题描述
我正在尝试创建一个c ++ dll和一个相应的VB控制台应用程序.我非常精通C ++,但对VB还是陌生的,所以我完成了一些教程.这是我的教程DLL的代码:
I am trying to create a c++ dll and a corresponding VB console application. I am very C++ savvy but new to VB so I went through a couple tutorials. Here is the code for my tutorial DLL:
#include "stdafx.h"
extern "C"
{
int _stdcall GetIntValue()
{
return 8;
}
int _stdcall GetSum(int A, int B)
{
return (A + B);
}
}
我也有一个.def文件,其中声明了两个函数.因为我有一个.def文件,所以我从代码中删除了__declspec(dllexport)并添加了extern"C".我的导出函数未在.lib文件中修饰.
我的VB应用程序如下所示:
I also have a .def file with the two functions declared in it. Since I have a .def file I removed the __declspec(dllexport) from the code and added extern "C". My exported functions are not decorated in the .lib file.
My VB Application looks like this:
Module Module1
Private Declare Function GetIntValue Lib _
"..\..\..\Release\Test_SimpleDLL.dll" () As Long
Private Declare Function GetSum Lib _
"..\..\..\Release\Test_SimpleDLL.dll" _
(ByVal inA As Long, _
ByVal inB As Long) As Long
Sub Main()
Console.WriteLine(GetIntValue())
Console.WriteLine(GetSum(5, 12))
End Sub
End Module
当我运行它时,我得到奇怪的结果.有时我会像第一次拨打电话一样获得值"8",但是大多数情况下,它是一个怪异的大数字,并且并不总是相同的怪异数字.
第二个调用几乎总是返回值"5",但有时还会返回不同的怪异长号.
我已经尝试了所有我能想到的.有任何想法吗?谢谢.
Caleb
When I run it I get weird results. Sometimes I get the value ''8'' like I am supposed to for the first call, but most of the time it is some weird big number and it is not always the same weird number.
The second call almost always returns the value ''5'', but sometimes it also returns differing weird long numbers.
I have tried everything I can think of. Any ideas? Thanks.
Caleb
推荐答案
这篇关于如何从VB调用C ++ dll函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!