Click to See Complete Forum and Search --> : Callback Function ?


VipulPathak
March 27th, 2001, 09:09 PM
Hello All Experts !!

I want to register my VB function as a CallBack function in a DLL function.

viz. :

Declare Function lineInitialize Lib "tapi32.lib" (byref lphLineApp as Long, byval hInstance as Long, byval lpfnCallback as Long, byref lpszAppName as string, byref lpdwNumDevs as Double) as Long

Rem: The 3rd Parameter is the Name of CALLBACK Function. Below is how i tried to call it -
lineInitialize lphLineApp, App.hInstance, MyTapiCallback, App.EXEName, lpdwNumDevs




This function is defined in "Tapi32.Lib" and is fairely easy to do it in Visual C++ to register a function as
CALLBACK. but how can i register my one VB function as CALLBACK in the lineInitialze() function.

Below is the entire code, have a look -



Dim OriginalWidth as Integer, OriginalHeight as Integer
Dim lphLineApp as Long, lpdwNumDevs

private Sub cmdShutdown_Click()
Unload me
End Sub

private Sub Form_Load()
OriginalWidth = me.Width
OriginalHeight = me.Height
me.optCallType(0).Value = true ' 0=Voice, 1=Data, 2=Fax
lphLineApp = 0
lpdwNumDevs = 0
lineInitialize lphLineApp, App.hInstance, MyTapiCallback, App.EXEName, lpdwNumDevs
End Sub

private Sub Form_Resize()
If me.WindowState <> vbMinimized then
me.Width = OriginalWidth
me.Height = OriginalHeight
End If
End Sub

public Function MyTapiCallback(byval hDevice as Long, byval dwMessage as Long, byval dwInstance as Long, byval Param1 as Long, byval Param2 as Long, byval Param3 as Long)
Rem: This should be the CALLBACK function
MsgBox "Hello Callback Event", vbOKOnly, "TAPI 1.4"
End Function




CAN SOMEONE HELP ??

Thanks in Advance !!





I am new to Windows Programming. I have Win32 API Programming in my studies at this Semester.
So If I ask too much or Non-Sense, Please Ignore !

-Vipul Pathak.
Indore, (MP) INDIA.
ICQ# 102045224

cksiow
March 28th, 2001, 12:25 AM
AddressOf operator is what you need. You need to declare the callback function in a module first.

change this line
lineInitialize lphLineApp, App.hInstance, MyTapiCallback, App.EXEName, lpdwNumDevs

to lineInitialize lphLineApp, App.hInstance, AddressOf MyTapiCallback, App.EXEName, lpdwNumDevs

hope this help.

cksiow
http://vblib.virtualave.net - share our codes

kwade
March 28th, 2001, 08:59 AM
Just to clarify. Your callback function needs to reside in a standard module (*.bas) extension and not in a form. Then use the AddressOf operator with the 3rd argument when calling the DLL function.

Good Luck.

Kenny