Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Writing a simple DLL for use in VB

Status
Not open for further replies.

soas

Technical User
Aug 3, 2001
49
0
0
US
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 &quot;testdll.dll&quot; (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
 
I figured out what the problem was no more than an hour or so after I posted this... The data types from VB to VC++ dont match and it was causing it to freeze I guess..

I changed the data types in VB to long instead of integer and it worked, I am sorry for taking up space on the forum, but I guess it could end up helping someone else if they have the same question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top