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);
}
}
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
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