Jump to content

[Solved]Callback function and Objet


Recommended Posts


I follow my project about the use of DirectInput with Autoit

If i can create the interface correctly with the DirectInput8create Function

I have a problem when i want to use Callback function to enum Devices. ("bad callee")

i have Written this piece of code, but is it the the good syntax to callback the function _EnumJoystickProc?

i have looked in this forum and Google, but no samples of code using callback and Objet, may be its no possible?

Or there is a special syntax to callback function with autoit objet?

Local $oDirectInput8 = ObjCreateInterface ( $sCLSID_DirectInput8 , $sIID_IDirectInput8 ,$dtagIDirectInput8 )
; Create callback function
Global $handle = DllCallbackRegister("_EnumJoystickProc", "BOOL", "ptr;ptr")
$aa=$oDirectInput8.EnumDevices($DI8DEVCLASS_ALL,DllCallbackGetPtr($handle), 0, $DIEDFL_ATTACHEDONLY)
; MsgBox(0,hex($aa,8),$oDirectInput8)
Func _EnumJoystickProc($pDIinstance, $pContexte)
     Return $DIENUM_STOP



Edited by Frenchy
Link to comment
Share on other sites

You should post runnable code if you want precise help. Ten things could be wrong with the code that you aren't posting.

What I can see in your posted code is that you don't initialize DirectInput object. If you use ObjCreateInterface() then you have to call Initialize method before you start working with the object. It's all there on MSDN page for DirectInput8Create, just read carefully.




Link to comment
Share on other sites

Okay Trancexx, i have poste a runnable code (sorry for my english..)

So when i try to initialize the DirectInput interface

i have this com error: ! COM Error ! Number: 0x80020010 - Invalid Callee

So i have tried to understand.. iahev redad MSDM to understand better COM objet, so the objet interface to be correctly created, but Initialize Fails..

the function in C++ gives

HRESULT Initialize(


DWORD dwVersion


But when i test the VarGetType of Handle of Dll ($hDINPUT) it says Int32, but in help Autoit, Handle is pointer.. Dunno if the cause of error..

I need some light...!!

;#include "WINAPI.au3"
Opt("GUIOnEventMode", 1)
; Error monitoring
Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
ConsoleWrite("! COM Error !  Number: 0x" & Hex($oError.number, 8) & "   ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF)
EndFunc   ;==>_ErrFunc
; DirectInput related constants
Global Const $DIDEVTYPE_DEVICE      = 1
Global Const $DIDEVTYPE_MOUSE        = 2
Global Const $DIDEVTYPE_KEYBOARD      = 3
Global Const $DIDEVTYPE_JOYSTICK      = 4
Global Const $DI8DEVCLASS_ALL        = 0
Global Const $DI8DEVCLASS_DEVICE      = 1
Global Const $DI8DEVCLASS_POINTER    = 2
Global Const $DI8DEVCLASS_KEYBOARD    = 3
Global Const $DI8DEVCLASS_GAMECTRL    = 4
Global Const $DI8DEVTYPE_DEVICE    = 0x11
Global Const $DI8DEVTYPE_MOUSE      = 0x12
Global Const $DI8DEVTYPE_KEYBOARD    = 0x13
Global Const $DI8DEVTYPE_JOYSTICK    = 0x14
Global Const $DI8DEVTYPE_GAMEPAD      = 0x15
Global Const $DI8DEVTYPE_DRIVING      = 0x16
Global Const $DI8DEVTYPE_FLIGHT    = 0x17
Global Const $DI8DEVTYPE_1STPERSON    = 0x18
Global Const $DI8DEVTYPE_DEVICECTRL   = 0x19
Global Const $DI8DEVTYPE_REMOTE    = 0x1B
Global Const $DIEDFL_ALLDEVICES    = 0x00000000
Global Const $DIEDFL_ATTACHEDONLY    = 0x00000001
Global Const $DIEDFL_FORCEFEEDBACK    = 0x00000100
Global Const $DIEDFL_INCLUDEALIASES   = 0x00010000
Global Const $DIEDFL_INCLUDEPHANTOMS  = 0x00020000
Global Const $DIEDFL_INCLUDEHIDDEN    = 0x00040000
Global Const $DIENUM_STOP            = 0
Global Const $DIENUM_CONTINUE        = 1
Global Const $DIRECTINPUT_VERSION = 0x0800
Global const $sIID_IDirectInput8  = "{BF798031-483A-4DA2-AA99-5D64ED369700}"
Global const $sCLSID_DirectInput8 = "{25E609E4-B259-11CF-BFC7-444553540000}"
; Used Dlls
Global Const $hDINPUT = DllOpen("dinput8.dll")
; Tag interface
Global $dtagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _
  "AddRef dword();" & _
  "Release dword();"
Global $dtagIDirectInput8W = $dtagIUnknown & _
"CreateDevice hresult(ptr;ptr*;ptr);" & _
"EnumDevices hresult(uint;ptr;ptr;uint);" & _
"GetDeviceStatus hresult(ptr);" & _
"RunControlPanel hresult(ptr;uint);" & _
"Initialize hresult(ptr;uint);" & _
"FindDevice hresult(ptr;wstr;ptr);" & _
"EnumDevicesBySemantics hresult(wstr;ptr;ptr;ptr;uint);" & _
"ConfigureDevices hresult(ptr;ptr;uint;ptr);"
; IDirect3D9 interface pointer
Global $oDirectInput8 = ObjCreateInterface ( $sCLSID_DirectInput8 , $sIID_IDirectInput8 , $dtagIDirectInput8W)
ConsoleWrite ("$oDirectInput8 is an Objet Interface -> " & (IsObj($oDirectInput8) = True) & @CRLF)
ConsoleWrite ("$hDINPUT VarGetType -> " & VarGetType($hDINPUT) & @CRLF)
$oDirectInput8.Initialize($hDINPUT, $DIRECTINPUT_VERSION)
; Create callback function
Global $handle = DllCallbackRegister("EnumJoystickProc", "BOOL", "ptr;ptr")
$result=$oDirectInput8.EnumDevices($DI8DEVCLASS_ALL, DllCallbackGetPtr($handle), 0, $DIEDFL_ALLDEVICES)
$oDirectInput8 = 0
Func EnumJoystickProc($p, $d)
Static Local $index=1
ConsoleWrite("Enter in Callback function " & $index )
$index = $index +1
; On Exit Function
Func _Quit()
EndFunc   ;==>_Quit

Regards Terry

Link to comment
Share on other sites

Don't look inside before you get it working.

#include <WinApi.au3>

Global Const $sCLSID_DirectInput = "{25E609E4-B259-11CF-BFC7-444553540000}"
Global Const $sIID_IDirectInput8W = "{BF798031-483A-4DA2-AA99-5D64ED369700}"
Global Const $tagIDirectInput8 = "CreateDevice hresult(clsid;ptr*;ptr);" & _
        "EnumDevices hresult(dword;ptr;ptr;dword);" & _
        "GetDeviceStatus hresult(clsid);" & _
        "RunControlPanel hresult(hwnd;dword);" & _
        "Initialize hresult(handle;dword);" & _
        "FindDevice hresult(clsid;wstr;clsid*);" & _
        "EnumDevicesBySemantics hresult(wstr;ptr;ptr;ptr;dword);" & _
        "ConfigureDevices hresult(ptr;ptr;dword;ptr);"

Global Const $DIRECTINPUT_VERSION = 0x0800
Global Const $DIENUM_CONTINUE = 1
Global Const $DI8DEVCLASS_ALL = 0
Global Const $DIEDFL_ATTACHEDONLY = 0x00000001

Global $oIDirectInput8 = ObjCreateInterface($sCLSID_DirectInput, $sIID_IDirectInput8W, $tagIDirectInput8)

$oIDirectInput8.Initialize(_WinAPI_GetModuleHandle(0), $DIRECTINPUT_VERSION)

Global $hCallback = DllCallbackRegister("_EnumAllProc", "bool", "ptr;ptr")

$oIDirectInput8.EnumDevices($DI8DEVCLASS_ALL, DllCallbackGetPtr($hCallback), 0, $DIEDFL_ATTACHEDONLY)

; Callback definition
Func _EnumAllProc($pDIinstance, $pContext)
    If $pDIinstance Then
        Local $tDIDEVICEINSTANCE = DllStructCreate("dword dwSize;" & _
                "byte guidInstance[16];" & _
                "byte guidProduct[16];" & _
                "dword dwDevType;" & _
                "wchar tszInstanceName[260];" & _
                "wchar tszProductName[260];" & _
                "byte guidFFDriver[16];" & _
                "word wUsagePage;" & _
                "word wUsage;", _

        ConsoleWrite("guidInstance = " & _WinAPI_StringFromGUID(DllStructGetPtr($tDIDEVICEINSTANCE, "guidInstance")) & @CRLF)
        ConsoleWrite("guidProduct = " & _WinAPI_StringFromGUID(DllStructGetPtr($tDIDEVICEINSTANCE, "guidProduct")) & @CRLF)

        ConsoleWrite("tszInstanceName = " & DllStructGetData($tDIDEVICEINSTANCE, "tszInstanceName") & @CRLF)
        ConsoleWrite("tszProductName = " & DllStructGetData($tDIDEVICEINSTANCE, "tszProductName") & @CRLF)

        ConsoleWrite("guidFFDriver = " & _WinAPI_StringFromGUID(DllStructGetPtr($tDIDEVICEINSTANCE, "guidFFDriver")) & @CRLF)

        ConsoleWrite("wUsagePage = " & DllStructGetData($tDIDEVICEINSTANCE, "wUsagePage") & @CRLF)
        ConsoleWrite("wUsage = " & DllStructGetData($tDIDEVICEINSTANCE, "wUsage") & @CRLF)






Link to comment
Share on other sites

Okay Trancexx i understant better the sentence in help file about the 3 methods automatically added in Objet COM, and i understand why my program fails (certainly an offset problem with function)

i have to increase my skills in english langage !!

Thanks again for your time to help me..With Com objet i have discovered a part of autoit i have never opened!!

In fact all is possible with Autoit!!

i really appreciate


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...