This program is pointless, I was writing it to try out things before I wrote what I needed.. What this is doing is comparing vb multiplication time, to c++ multiplication time.. which I realize this might not be a great way, but thats not the point. I am not sure what the problem is, I know its something to do with how I am using pointers, when I call it from VB it freezes my program.. But if I change AB=*A to AB=150 and BB=*B to BB=150, the dll works fine, it returns the right value and there are no problems.. I have tried rewriting it a bunch of ways.. I know I must be doing something fundamentally wrong, this is the first time I have attempted to write a dll and I just recently discovered how nice it can be to use DLL's in VB apps..
Here is the code below, I am using MSVC++ 6.0 and MSVB 5.0
Test.cpp
int Test(int *A, int *B);
int Test(int *A, int *B)
{
int x,y,z;
int AB,BB;
long c;
AB=*B;
BB=*A;
for(z=0;z<=100;z++)
for(y=0;y<=BB;y++)
for(x=0;x<=AB;x++)
c = x*y;
return *B+*A;
}
Test.def
LIBRARY testdll
EXPORTS
Test
VB code
Private Declare Function Test Lib "testdll.dll" (A As Integer, B As Integer) As Integer
Private Sub Command1_Click()
Dim A As Integer, B As Integer, C As Integer, D As Long, T As Single
T = Timer
D = Test(150, 150)
Print Timer - T
T = Timer
For C = 0 To 100
For B = 0 To 150
For A = 0 To 150
D = A * B
Next
Next
Next
Print Timer - T
End Sub
The VB code just calls it and checks how much time it takes compared to doing pretty much the same thing in VB... The dll compiles without problems, the vb of course works without problems.. I obviously dont know how to use pointers or at least using them in DLL's, maybe I just went about writing the DLL wrong, but it seems to work aside from using pointers.. if anyone could tell me what I am doing wrong I would really appreciate it
Here is the code below, I am using MSVC++ 6.0 and MSVB 5.0
Test.cpp
int Test(int *A, int *B);
int Test(int *A, int *B)
{
int x,y,z;
int AB,BB;
long c;
AB=*B;
BB=*A;
for(z=0;z<=100;z++)
for(y=0;y<=BB;y++)
for(x=0;x<=AB;x++)
c = x*y;
return *B+*A;
}
Test.def
LIBRARY testdll
EXPORTS
Test
VB code
Private Declare Function Test Lib "testdll.dll" (A As Integer, B As Integer) As Integer
Private Sub Command1_Click()
Dim A As Integer, B As Integer, C As Integer, D As Long, T As Single
T = Timer
D = Test(150, 150)
Print Timer - T
T = Timer
For C = 0 To 100
For B = 0 To 150
For A = 0 To 150
D = A * B
Next
Next
Next
Print Timer - T
End Sub
The VB code just calls it and checks how much time it takes compared to doing pretty much the same thing in VB... The dll compiles without problems, the vb of course works without problems.. I obviously dont know how to use pointers or at least using them in DLL's, maybe I just went about writing the DLL wrong, but it seems to work aside from using pointers.. if anyone could tell me what I am doing wrong I would really appreciate it