Hallo.
Folgender noch nicht vollständig entwickelter Code wird auf meinem Notebook mit 2 Akkuks ausgeführt. Der code gibt leider noch nicht das aus, was er soll ( 2 Akkus, wenn auch 2 drinn sind), aber das tut hier nichts zur Sache.
Kompeliere ich das nun unter PB4
Code: Alles auswählen
;http://www.google.com/codesearch
;http://msdn2.microsoft.com/en-us/library/bb204769.aspx
;http://search.msdn.microsoft.com/search/Redirect.aspx?title=Enumerating+Battery+Devices+&url=http://msdn2.microsoft.com/en-us/library/bb204769.aspx
#DIGCF_PRESENT = $00000002
#DIGCF_DEVICEINTERFACE = $00000010
Prototype SDEDI(a,b,c,d,e)
;Prototype SDEDID(a,b,c,d,e,f)
If OpenLibrary(0,"Setupapi.dll")
SetupDiEnumDeviceInterfaces.SDEDI = GetFunction(0,"SetupDiEnumDeviceInterfaces")
If GetFunction(0,"SetupDiEnumDeviceInterfaces") = 0
MessageRequester("error","")
EndIf
Debug "ok"
;SetupDiGetDeviceInterfaceDetail.SDEDID = GetFunction(0,"SetupDiGetDeviceInterfaceDetailW")
If 0;GetFunction(0,"SetupDiGetDeviceInterfaceDetailW") = 0
MessageRequester("error","SetupDiGetDeviceInterfaceDetail")
EndIf
Debug "ok"
EndIf
Structure SP_DEVICE_INTERFACE_DATA
cbSize.l
InterfaceClassGuid.GUID
flags.l
reserved.l
EndStructure
NewList ll_did.SP_DEVICE_INTERFACE_DATA()
ClearList(ll_did())
did.SP_DEVICE_INTERFACE_DATA
did\cbSize = SizeOf(did)
tempSizeOf_ll_did.SP_DEVICE_INTERFACE_DATA
;did\cbSize = SizeOf(did)
SizeOf_ll_did = SizeOf(tempSizeOf_ll_did)
hdev = SetupDiGetClassDevs_(?GUID_DEVICE_BATTERY,0,0,#DIGCF_PRESENT | #DIGCF_DEVICEINTERFACE)
;hdev = SetupDiGetClassDevs_(?GUID_DEVICE_BATTERY,0,0,0)
Debug "hdev: " +Str (hdev)
;Debug "GetLastError: " + Str(GetLastError_()) ;#ERROR_NO_MORE_ITEMS
If hdev <> #INVALID_HANDLE_VALUE ;-1
idev = 0
Repeat
; SetupDiEnumDeviceInterfaces(hdev,0,?GUID_DEVICE_BATTERY,0,@did)
AddElement(ll_did())
ll_did()\cbSize = SizeOf_ll_did
;did\cbSize = SizeOf(did)
;ReturnSetupDiEnumDeviceInterfaces = SetupDiEnumDeviceInterfaces(hdev,0,?GUID_DEVICE_BATTERY,idev,@did)
ReturnSetupDiEnumDeviceInterfaces = SetupDiEnumDeviceInterfaces(hdev,0,?GUID_DEVICE_BATTERY,idev,@ll_did())
ReturnGetLastErrorSetupDiEnumDeviceInterfaces = GetLastError_()
If ReturnSetupDiEnumDeviceInterfaces > 0
Debug "SetupDiEnumDeviceInterfaces: " + Str( ReturnSetupDiEnumDeviceInterfaces )
Debug "cbSize: " + Str(ll_did()\cbSize)
Debug "InterfaceClassGuid: " + Str(ll_did()\InterfaceClassGuid) + " : " + Str(PeekQ(ll_did()\InterfaceClassGuid)) + " : " + Str(PeekQ(8+ll_did()\InterfaceClassGuid))
Debug "flags: " + Str(Cflags)
;Debug "InterfaceClassGuid: " + Str(did\InterfaceClassGuid) + " : " + Str(PeekQ(did\InterfaceClassGuid)) + " : " + Str(PeekQ(8+did\InterfaceClassGuid))
;Debug "flags: " + Str(did\flags)
Debug "ReturnGetLastErrorSetupDiEnumDeviceInterfaces: " + Str(ReturnGetLastErrorSetupDiEnumDeviceInterfaces) ;#ERROR_NO_MORE_ITEMS
cbRequired.l = 0
;ReturnSetupDiGetDeviceInterfaceDetail = SetupDiGetDeviceInterfaceDetail(hdev,@ll_did(),0,0,cbRequired,0)
Debug "SetupDiGetDeviceInterfaceDetail: " + Str(ReturnSetupDiGetDeviceInterfaceDetail)
Debug "cbRequired: " + Str(cbRequired)
Debug "-----"
Else
Debug "ReturnGetLastErrorSetupDiEnumDeviceInterfaces: " + Str(ReturnGetLastErrorSetupDiEnumDeviceInterfaces) ;#ERROR_NO_MORE_ITEMS
DeleteElement(ll_did())
EndIf
;[21:10:00] GetLastError: 1784
idev + 1
Until idev => 100 Or ReturnGetLastErrorSetupDiEnumDeviceInterfaces = #ERROR_NO_MORE_ITEMS ;259
; SetupDiDestroyDeviceInfoList_(hdev)
EndIf
DataSection
GUID_DEVICE_BATTERY:
Data.l $72631E54
;Data.l $72631E54
Data.w $78A4
Data.w $11D0
Data.b $BC, $F7, $00, $AA, $00, $B7, $B3, $2A
EndDataSection
DAs sollte korrekt sein. Zum Schluß wird 259 ausgegeben durch getlasterror.[01:50:46] ok
[01:50:46] ok
[01:50:46] hdev: 1336552
[01:50:46] SetupDiEnumDeviceInterfaces: 1
[01:50:46] cbSize: 28
[01:50:46] InterfaceClassGuid: 8986524 : 1919098452 : -1442777156
[01:50:46] flags: 0
[01:50:46] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:50:46] SetupDiGetDeviceInterfaceDetail: 0
[01:50:46] cbRequired: 0
[01:50:46] -----
[01:50:46] SetupDiEnumDeviceInterfaces: 1
[01:50:46] cbSize: 28
[01:50:46] InterfaceClassGuid: 8986572 : 1919098452 : -1442777156
[01:50:46] flags: 0
[01:50:46] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:50:46] SetupDiGetDeviceInterfaceDetail: 0
[01:50:46] cbRequired: 0
[01:50:46] -----
[01:50:46] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 259
Aktiviere ich nun "Threadsicher" funktioniert getlasterror wohl nicht mehr richtig. Es kommt zu folgender Ausgabe:
Was kann das denn sein? THreadsicher ist für mich sehr wichtig.[01:52:08] ok
[01:52:08] ok
[01:52:08] hdev: 1336680
[01:52:08] SetupDiEnumDeviceInterfaces: 1
[01:52:08] cbSize: 28
[01:52:08] InterfaceClassGuid: 8986540 : 1919098452 : -1442777156
[01:52:08] flags: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] SetupDiGetDeviceInterfaceDetail: 0
[01:52:08] cbRequired: 0
[01:52:08] -----
[01:52:08] SetupDiEnumDeviceInterfaces: 1
[01:52:08] cbSize: 28
[01:52:08] InterfaceClassGuid: 8986588 : 1919098452 : -1442777156
[01:52:08] flags: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] SetupDiGetDeviceInterfaceDetail: 0
[01:52:08] cbRequired: 0
[01:52:08] -----
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
[01:52:08] ReturnGetLastErrorSetupDiEnumDeviceInterfaces: 0
Gruß Toshy