Clairvoyant1332
Programmer
As an excercise, I've written a simple DLL in Visual C to be called from Visual Basic, but I'm having a little trouble getting the datatypes to match up. I'm using VB6 and VC6. The error I get from VB is "Bad DLL calling convention"
This code will work under VB/VC.NET, but I'd rather not use .NET in this case as I'd like to avoid having to deploy the .NET framework for the app that will use this functionality.
Thanks,
Dennis
vctest.cpp:
#include "stdafx.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
int vcadd(int a, int b)
{
return a+b;
}
vctest.def:
LIBRARY vctest
EXPORTS
vcadd
vbtest.vb:
Declare Function vcadd Lib "../../vctest/debug/vctest.dll" (ByVal a As Integer, ByVal b As Integer) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s1 As Integer
Dim s2 As Integer
Dim s3 As Integer
s1 = 5
s2 = 8
s3 = vcadd(s1, s2)
MsgBox("s3=" & s3)
End Sub
This code will work under VB/VC.NET, but I'd rather not use .NET in this case as I'd like to avoid having to deploy the .NET framework for the app that will use this functionality.
Thanks,
Dennis
vctest.cpp:
#include "stdafx.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
int vcadd(int a, int b)
{
return a+b;
}
vctest.def:
LIBRARY vctest
EXPORTS
vcadd
vbtest.vb:
Declare Function vcadd Lib "../../vctest/debug/vctest.dll" (ByVal a As Integer, ByVal b As Integer) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s1 As Integer
Dim s2 As Integer
Dim s3 As Integer
s1 = 5
s2 = 8
s3 = vcadd(s1, s2)
MsgBox("s3=" & s3)
End Sub