ActiveX - Visual Basic 6.0 - ActiveX - mcHID.dll

   
Vista:

Visual Basic 6.0 - ActiveX - mcHID.dll

Publicado por Lucas Palomba lucaspalomba@hotmail.com (1 intervención) el 15/11/2011 14:12:47
Buen dia muchachos y muchachas espero que me puedan ayudar en este problema que tengo , quedo a su disposicion les comento que me esta pasando:
Tengo funcionando en visual basic un programa que lee las entradas analogicas/digitales y le puedo enviar datos para encender salidas. El mismo usa las lirerias de microchip mcHID.dll y funciona a la perfeccion cuando compilo el .exe
Estoy queriendo hacer un ActiveX (.ocx) para poder "llamarlo" desde un proyecto nuevo y no tener que cargar ningun modulo mas que el componente .ocx
Resulta que cuando armo la ocx, con el mismo modulo (HIDDLLInterface) la interface conecta y ademas puedo enviar comandos para activar las salidas. El problema esta en la lectura de las entradas, no logro leer el estado de ninguna de ellas.
Para conectar, desde el formulario del .exe llamo a la funcion ConnectToHID cuando carga el formulario de la siguiente forma:

Private Sub Form_Load()
ConnectToHID (Me.hwnd)
End Sub
Si esto lo quiero hacer con el .ocx, cuando hago un proyecto nuevo, pongo en el FormLoad, la funcion "conectar" (en la ocx tengo creada una funcion que se llama "conectar" de la siguiente forma:

Public Function Conectar()
ConnectToHID (Me.hwnd)
End Function

solo logro que se establezca la coneccion y puedo enviar datos, pero no puedo leer el valor de las entradas analogicas/digitales.

Creo que el problema lo estoy teniendo en el Conectar (Me.hwnd) pero no logro hacerlo funcionar, ya que no me doy cuenta como se utiliza el hwnd dentro de la ocx.
Dejo como referencia el modulo HIDDLLInterface que utilizo en ambos casos (.exe y .ocx).

Option Explicit

' HID interface API declarations...
Declare Function hidConnect Lib "mcHID.dll" Alias "Connect" (ByVal pHostWin As Long) As Boolean
Declare Function hidDisconnect Lib "mcHID.dll" Alias "Disconnect" () As Boolean
Declare Function hidGetItem Lib "mcHID.dll" Alias "GetItem" (ByVal pIndex As Long) As Long
Declare Function hidGetItemCount Lib "mcHID.dll" Alias "GetItemCount" () As Long
Declare Function hidRead Lib "mcHID.dll" Alias "Read" (ByVal pHandle As Long, ByRef pData As Byte) As Boolean
Declare Function hidWrite Lib "mcHID.dll" Alias "Write" (ByVal pHandle As Long, ByRef pData As Byte) As Boolean
Declare Function hidReadEx Lib "mcHID.dll" Alias "ReadEx" (ByVal pVendorID As Long, ByVal pProductID As Long, ByRef pData As Byte) As Boolean
Declare Function hidWriteEx Lib "mcHID.dll" Alias "WriteEx" (ByVal pVendorID As Long, ByVal pProductID As Long, ByRef pData As Byte) As Boolean
Declare Function hidGetHandle Lib "mcHID.dll" Alias "GetHandle" (ByVal pVendorID As Long, ByVal pProductID As Long) As Long
Declare Function hidGetVendorID Lib "mcHID.dll" Alias "GetVendorID" (ByVal pHandle As Long) As Long
Declare Function hidGetProductID Lib "mcHID.dll" Alias "GetProductID" (ByVal pHandle As Long) As Long
Declare Function hidGetVersion Lib "mcHID.dll" Alias "GetVersion" (ByVal pHandle As Long) As Long
Declare Function hidGetVendorName Lib "mcHID.dll" Alias "GetVendorName" (ByVal pHandle As Long, ByVal pText As String, ByVal pLen As Long) As Long
Declare Function hidGetProductName Lib "mcHID.dll" Alias "GetProductName" (ByVal pHandle As Long, ByVal pText As String, ByVal pLen As Long) As Long
Declare Function hidGetSerialNumber Lib "mcHID.dll" Alias "GetSerialNumber" (ByVal pHandle As Long, ByVal pText As String, ByVal pLen As Long) As Long
Declare Function hidGetInputReportLength Lib "mcHID.dll" Alias "GetInputReportLength" (ByVal pHandle As Long) As Long
Declare Function hidGetOutputReportLength Lib "mcHID.dll" Alias "GetOutputReportLength" (ByVal pHandle As Long) As Long
Declare Sub hidSetReadNotify Lib "mcHID.dll" Alias "SetReadNotify" (ByVal pHandle As Long, ByVal pValue As Boolean)
Declare Function hidIsReadNotifyEnabled Lib "mcHID.dll" Alias "IsReadNotifyEnabled" (ByVal pHandle As Long) As Boolean
Declare Function hidIsAvailable Lib "mcHID.dll" Alias "IsAvailable" (ByVal pVendorID As Long, ByVal pProductID As Long) As Boolean

' windows API declarations - used to set up messaging...
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

' windows API Constants
Private Const WM_APP = 32768
Private Const GWL_WNDPROC = -4

' HID message constants
Private Const WM_HID_EVENT = WM_APP + 200
Private Const NOTIFY_PLUGGED = 1
Private Const NOTIFY_UNPLUGGED = 2
Private Const NOTIFY_CHANGED = 3
Private Const NOTIFY_READ = 4

' Set up a windows hook to receive notification
' messages from the HID controller DLL - then connect
' to the controller
Public Function ConnectToHID(ByVal pHostWin As Long) As Boolean
FWinHandle = pHostWin
ConnectToHID = hidConnect(FWinHandle)
FPrevWinProc = SetWindowLong(FWinHandle, GWL_WNDPROC, AddressOf WinProc)
End Function

' Unhook from the HID controller and disconnect...
Public Function DisconnectFromHID() As Boolean
DisconnectFromHID = hidDisconnect
SetWindowLong FWinHandle, GWL_WNDPROC, FPrevWinProc
End Function

' This is the procedure that intercepts the HID controller messages...
Private Function WinProc(ByVal pHWnd As Long, ByVal pMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If pMsg = WM_HID_EVENT Then
Select Case wParam

' HID device has been plugged message...
Case Is = NOTIFY_PLUGGED
MainForm.OnPlugged (lParam)
' HID device has been unplugged
Case Is = NOTIFY_UNPLUGGED
MainForm.OnUnplugged (lParam)

' controller has changed...
Case Is = NOTIFY_CHANGED
MainForm.OnChanged
' read event...
Case Is = NOTIFY_READ
MainForm.OnRead (lParam)
End Select

End If

' next...
WinProc = CallWindowProc(FPrevWinProc, pHWnd, pMsg, wParam, lParam)

End Function



LES Agradeceria si es posible que me den sus opiniones y detalles dell hwnd y demas para que pueda sacar el proyecto a adelante..Muchas gracias y espero novedades
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder