Dll issue

G

Guest

I use the C++ to write a dll and call the dll using VB6

VC++ Code

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserve


return TRUE


int WINAPI MyDLLAdd(int d1, int d2

return (d1+d2)


int WINAPI MyDLLSub(int d1, int d2

return (d1-d2)


VB code

Declare Function MyAdd Lib "MyDLL.dll" Alias "MyDLLAdd" (ByVal data1 As Integer, ByVal data2 As Integer) As Intege
Private Sub Calc_Click(
Dim m As Intege
Dim n As Intege

m = Val(Text1.Text
n = Val(Text2.Text
Text3.Text = MyAdd(m, n
End Su

I run the VB and get the right answer. But when I debug my dll using VC++6. if I call MyAdd(3,2), then MyDLLAdd(int d1, int d2) d1(d1=1073741826) is not 3 and d2(d2=1074266115) is not 2.

What is wrong?
 
D

David Lowndes

kathy,

A (32-bit) C++ integer is 32-bit while a VB6 integer is only 16 bit -
so for your VB6 definitions, use Long instead.

Dave
 

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