I use the C++.NET to write a dll and call this dll using VB6.
VC++ Code
#include "stdafx.h
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserve
return TRUE
extern "C" __declspec(dllexport) int SPS_Add ( int i1, int i2
int sum
sum = i1 + i2
return (sum)
VB Code
Sub Mai
Declare Function SPS_Add Lib "SPS.dll" (ByVal i1 As Integer, ByVal i2 As Integer) As Intege
Dim a1 As Integer, a2 As Integer, sum As Intege
Dim temp1 As Strin
a1 =
a2 =
sum = SPS_Add(a1, a2
temp1 = a1 & " + " & a2 & " = " & su
MsgBox temp
End Su
I run the VB and get an error: "Bad DLL Calling Convention.". What is wrong
S.N. Yan
03/30/2004
Mattias Sj?gren - 30 Mar 2004 15:36 GMT
>I run the VB and get an error: "Bad DLL Calling Convention.". What is wrong?
Your exported function must use the stdcall calling convention.
extern "C" __declspec(dllexport) int __stdcall SPS_Add ( int i1, int
i2 )
Oh, and in VB6 Integer is only 16 bits, so you should use Longs in the
Declare statement.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.