Re: Problems with Callbacks
You're likely going to have to use either Integer or IntPtr in the place of any Long data types.
This can essentially be a guessing game without full documentation. Based on the names of the properties and how they're being used, I've come up with this:
Code:
Public Class Form1
Public Declare Function CLIENT_Init Lib "dhnetsdk.dll" (ByVal fDisConnect As Integer, _
ByVal wDVRPort As Integer) As Integer
'Login API
Public Declare Function CLIENT_Login Lib "dhnetsdk.dll" (ByVal pchDVRIP As String, ByVal wDVRPort As Integer, ByVal pchUserName As String, ByVal pchPassword As String, lpDeviceInfo As NET_DEVICEINFO, ByRef err As NET_RET_ERROR) As Integer
'Logout device
Public Declare Function CLIENT_Logout Lib "dhnetsdk.dll" (ByVal lLoginID As Integer) As Integer
'Realplay API
Public Declare Function CLIENT_RealPlay Lib "dhnetsdk.dll" _
(ByVal lLoginID As Integer, ByVal nChannelID As Integer, ByVal hwnd As IntPtr) As Integer
Public Declare Function CLIENT_RealPlayEx Lib "dhnetsdk.dll" _
(ByVal lLoginID As Integer, ByVal nChannelID As Integer, ByVal hwnd As IntPtr, _
ByVal rType As Integer) As Integer
'Stop Realplay
Public Declare Function CLIENT_StopRealPlayEx Lib "dhnetsdk.dll" (ByVal lLoginID As Integer) As Integer
Public Declare Sub CLIENT_Cleanup Lib "dhnetsdk.dll" ()
'Alarm Liten API
Public Declare Function CLIENT_StartListen Lib "dhnetsdk.dll" (ByVal lLoginID As Integer) As Integer
'Mess callback API
Public Declare Function CLIENT_SetDVRMessCallBack Lib "dhnetsdk.dll" (ByVal fMessCallBack As IntPtr, _
ByVal dwUser As Integer) As Integer
Public Structure NET_DEVICEINFO
Public sSerialNumber As String
Public byAlarmInPortNum As Byte
Public byAlarmOutPortNum As Byte
Public byDiskNum As Byte
Public byDVRType As Byte
Public byChanNum As Byte
End Structure
Public Structure NET_RET_ERROR
Public errcode As Integer
End Structure
Public Sub IniFunc(ByVal lLoginID As Integer, ByVal pchDVRIP As Integer, ByVal nDVRPort As Integer, ByVal dwUser As Integer)
MessageBox.Show(lLoginID)
End Sub
Public Sub MessFunc(ByVal lCommand As Integer, _
ByVal lLoginID As Integer, ByVal pBuf As IntPtr, _
ByVal dwBufLen As Integer, ByVal pchDVRIP As Integer, _
ByVal nDVRPort As Integer, ByVal dwUser As Integer)
MessageBox.Show(lLoginID)
MessageBox.Show(pBuf)
MessageBox.Show(pchDVRIP)
End Sub
Public Function PtrToLong(ByVal func As IntPtr) As Integer
PtrToLong = func
End Function
Private bInited, bout As Boolean
Private hLoginId, hMonitorId As Integer
Private err As NET_RET_ERROR
Private devInfo As NET_DEVICEINFO
Private dd, longinid As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
bInited = CLIENT_Init(PtrToLong(AddressOf IniFunc), 0)
End Sub
End Class
Keep in mind that this is a total guess. If you have full API documentation or even if you have full working sourcecode from a VB6 app that referenced this API, we can give you a better answer.
I simply changed the datatypes. Some of the references to these methods may now be broken, which you'll also have to fix.
Re: Problems with Callbacks
You're supposed to pass delegates I believe. Not Longs or IntPrts. Define a delegate that corresponds with the callback expected and declare the API's parameter to use this delegate as its type. When calling, you pass the address of a method with the same signature as the callback.