Search the Community
Showing results for tags 'objectcreateinterface'.
-
Well an Implementation of IPortableDeviceManager Interface to get all Portable Device conected to our pc. #include <Array.au3> #include <WinAPICom.au3> Opt("MustDeclareVars", 1) Global Const $sCLSID_PortableDeviceManager = "{0af10cec-2ecd-4b92-9581-34f6ae0637f3}" Global Const $sIID_IPortableDeviceManager = "{a1567595-4c2f-4574-a6fa-ecef917b9a40}" Global Const $sTagIPortableDeviceManager = "GetDevices hresult(ptr;dword*); RefreshDeviceList hresult(); " & _ "GetDeviceFriendlyName hresult(wstr;wstr;dword*); GetDeviceDescription hresult(wstr;wstr;dword*); " & _ "GetDeviceManufacturer hresult(wstr;wstr;dword*); GetDeviceManufacturer hresult(wstr;wstr;ptr;dword*dword*); " & _ "GetPrivateDevices hresult(ptr;dword*)" Global Enum $eDevID, $eDevName, $eDevManufacturer, $eDevDescription Local $aPnPDevices = GetPortableDevices() If IsArray($aPnPDevices) Then _ArrayDisplay($aPnPDevices) ;~ Success: Return 0 ;~ Failure: Return 2DArray [n][4] |;[n][0]$eDevID, [n][1]$eDevName, [n][2]$eDevManufacturer,[n][3] $eDevDescription Func GetPortableDevices() Local $aDevicesInfo[0][0] ;[n][0]$eDevID, [n][1]$eDevName, [n][2]$eDevManufacturer,[n][3] $eDevDescription Local $oPortableDeviceManager = 0 Local $SizeofArray = 0 Local $hr = 0x80004005 ;E_Fail Just to Initialized <0 Local $taPnPDeviceIDs = 0 Local $tName = 0 $oPortableDeviceManager = ObjCreateInterface($sCLSID_PortableDeviceManager, $sIID_IPortableDeviceManager, $sTagIPortableDeviceManager) If Not IsObj($oPortableDeviceManager) Then Return 0 If FAILED($oPortableDeviceManager.GetDevices(Null, $SizeofArray)) Then Return 0 If $SizeofArray < 1 Then Return 0 $taPnPDeviceIDs = DllStructCreate("ptr[" & $SizeofArray & "]") If FAILED($oPortableDeviceManager.GetDevices(DllStructGetPtr($taPnPDeviceIDs), $SizeofArray)) Then Return 0 ReDim $aDevicesInfo[$SizeofArray][4] For $i = 0 To $SizeofArray - 1 $tName = DllStructCreate("wchar[512]", DllStructGetData($taPnPDeviceIDs, 1, $i + 1)) $aDevicesInfo[$i][$eDevID] = DllStructGetData($tName, 1) $aDevicesInfo[$i][$eDevName] = _GetFriendlyName($oPortableDeviceManager, $aDevicesInfo[$i][$eDevID]) $aDevicesInfo[$i][$eDevManufacturer] = _GetDeviceManufacturer($oPortableDeviceManager, $aDevicesInfo[$i][$eDevID]) $aDevicesInfo[$i][$eDevDescription] = _GetDeviceDescription($oPortableDeviceManager, $aDevicesInfo[$i][$eDevID]) $tName = 0 _WinAPI_CoTaskMemFree(DllStructGetData($taPnPDeviceIDs, 1, $i + 1)) Next Return $aDevicesInfo EndFunc ;==>GetPortableDevices Func _GetDeviceManufacturer($oInterface, $PnPDeviceID) Local $sString = "" $oInterface.GetDeviceManufacturer($PnPDeviceID, $sString, 128) Return $sString EndFunc ;==>_GetDeviceManufacturer Func _GetDeviceDescription($oInterface, $PnPDeviceID) Local $sString = "" Local Const $Size = 128 $oInterface.GetDeviceDescription($PnPDeviceID, $sString, 128) Return $sString EndFunc ;==>_GetDeviceDescription Func _GetFriendlyName($oInterface, $PnPDeviceID) Local $sString = "" Local Const $Size = 128 $oInterface.GetDeviceFriendlyName($PnPDeviceID, $sString, 128) Return $sString EndFunc ;==>_GetFriendlyName Func _GetProperty($oInterface, $PnPDeviceID) Local $sString = "" Local Const $Size = 128 $oInterface.GetDeviceFriendlyName($PnPDeviceID, $sString, 128) Return $sString EndFunc ;==>_GetProperty Func FAILED($hr) Return ($hr < 0) EndFunc ;==>FAILED Saludos