Link to home
Start Free TrialLog in
Avatar of fmufti
fmufti

asked on

Calling Dll in VB...

I wanted to call C dll in VB.
Can someone help me. Just mail me a CPP and DEF file for C Dll, and  source
code for VB having one function with one argument that is passed by VB to Function in C dll. I hope by working on that I'll able to do my required job( Making and calling complex functions).Email:fmufti@softhome.net
ASKER CERTIFIED SOLUTION
Avatar of MikeP090797
MikeP090797

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fmufti
fmufti

ASKER

Thanx u have give a pritty lenghty routine. I want a simple routine. So that I can understand it better. I write the fol code

int MyBeep(void)
{
// Beep
//MessageBeep( (WORD) -1 );
return 1;
}
int MyDelay( long wait )
{
// Delay.
Sleep(wait);
return 1;
}
in
VB I declare in module as:
Declare Function MyDelay Lib "C:\vb5prg\dll\mydll\Release\MyDll" (ByVal wait As Long) As Integer
Declare Function MyBeep Lib "C:\vb5prg\dll\mydll\Release\MyDll" () As Integer
I then made a button in a form with fol code:
Private Sub Command1_Click()
Dim l As Long
Dim p As Long
p = MyBeep
l = MyDelay(500)
End Sub
My Beep Message works fine as it does not take any arguments, but for MyDelay it gives error"Error 49, Bad Dll calling conversion. Can u guide me why. ? In fact I have to write a simple routine in VB which uses dll to send data on Parallel  port. That data is to be send from vb to dll.
I hope now u can be able to reply me more precisely.
Avatar of fmufti

ASKER

I have also define the functions as u have defined in DEF file.
The problem is with the declaration: In C++, int is 32 bit, so actualy there is no difference between it and long. In VB, Integer is 16 bit, so this is why the error occures. It should be:



Declare Function MyDelay Lib "C:\vb5prg\dll\mydll\Release\MyDll" (ByVal wait As Long) As Long
Declare Function MyBeep Lib "C:\vb5prg\dll\mydll\Release\MyDll" () As Long

Avatar of fmufti

ASKER

I have tried but again failure, my email is fmuti@softhome.net, can u mail the code that I have written after checking it on VC and VB. So that I can mail u if required in return the code and u'll be able to find the problem.
Just sent