Bad DLL Calling Cinvention

G

Guest

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
 
M

Mattias Sjögren

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top