Code: Alles auswählen
#DIGCF_DEFAULT = 1
#DIGCF_PRESENT = 2
#DIGCF_ALLCLASSES = 4
#DIGCF_PROFILE = 8
#DIGCF_DEVICEINTERFACE = 16
#SPDRP_DEVICEDESC = 0
#MAX_CLASS_NAME_LEN = 128
#DIREG_DEV = 1
#DIREG_DRV = 2
#DICS_FLAG_GLOBAL = 1
#DICS_FLAG_CONFIGSPECIFIC = 2
#SPDRP_DEVICEDESC = 0 ; ECP-Druckeranschluss
#SPDRP_HARDWAREID = 1 ; ACPI\PNP0401
#SPDRP_COMPATIBLEIDS = 2 ; (err13)
#SPDRP_SERVICE = 4 ; Parport
#SPDRP_CLASS = 7 ; Ports
#SPDRP_CLASSGUID = 8 ; {4D36E978-E325-11CE-BFC1-08002BE10318}
#SPDRP_DRIVER = 9 ; {4D36E978-E325-11CE-BFC1-08002BE10318}\0000
#SPDRP_CONFIGFLAGS = 10 ; 127 (Zahl=Long)
#SPDRP_MFG = 11 ; (Standardanschlusstypen)
#SPDRP_FRIENDLYNAME = 12 ; ECP-Druckeranschluss (LPT1)
#SPDRP_LOCATION_INFORMATION = 13 ; (err13)
#SPDRP_PHYSICAL_DEVICE_OBJECT_NAME = 14 ; \Device\0000005c
#SPDRP_CAPABILITIES = 15 ; 48 (Zahl=Long)
#SPDRP_UI_NUMBER = 16 ; (err13)
#SPDRP_UPPERFILTERS = 17 ; (err13)
#SPDRP_LOWERFILTERS = 18
#SPDRP_BUSTYPEGUID = 19
#SPDRP_LEGACYBUSTYPE = 20
#SPDRP_BUSNUMBER = 21
#SPDRP_ENUMERATOR_NAME = 22 ; ACPI
#SPDRP_SECURITY = 23
#SPDRP_SECURITY_SDS = 24
#SPDRP_DEVTYPE = 25
#SPDRP_EXCLUSIVE = 26
#SPDRP_CHARACTERISTICS = 27
#SPDRP_ADDRESS = 28
#SPDRP_UI_NUMBER_DESC_FORMAT = 30
Global NewList comports.s()
Structure SP_DEVICE_INTERFACE_DATA
cbSize.l
InterfaceClassGuid.GUID
Flags.l
Reserved.l
EndStructure
Structure SP_DEVINFO_DATA
cbSize.l
ClassGuid.GUID
DevInst.l
Reserved.l
EndStructure
Structure ComArrayStructure
ComPort.s
EndStructure
Procedure.s EnumComPorts()
zClassName.s="Ports"
PortName.s=""
DeviceInterfaceData.SP_DEVICE_INTERFACE_DATA
DeviceInfoData.SP_DEVINFO_DATA
hDeviceInfoSet.l=0
Size.l=0
hKeyDevice.l=0
DevCount.l=0
value.l=0
value=SetupDiClassGuidsFromName_(zClassName,0,0,@Size) ; only ask for size of array
If value=0
err=GetLastError_()
If err=#ERROR_INSUFFICIENT_BUFFER ; we will get this error and know the arraysize now
out.s+ "The data area passed to a system call is too small." +#CRLF$
out.s+ "RequiredSize : "+Str(Size) +#CRLF$
EndIf
If Size>0
Dim GuidArray.GUID(Size)
value=SetupDiClassGuidsFromName_(zClassName,@GuidArray(1),SizeOf(GUID)*Size,@Size)
If value>0
hDeviceInfoSet=SetupDiGetClassDevs_(@GuidArray(1),0,0,#DIGCF_PRESENT)
err=GetLastError_()
If err=#ERROR_IO_PENDING Or err=0
out.s+ "Overlapped I/O operation is in progress." +#CRLF$
If hDeviceInfoSet<>#INVALID_HANDLE_VALUE
DeviceInfoData\cbSize=SizeOf(DeviceInfoData)
DeviceInterfaceData\cbSize=SizeOf(DeviceInterfaceData)
NewList ComArray.ComArrayStructure()
Repeat
value=SetupDiEnumDeviceInfo_(hDeviceInfoSet,DevCount,@DeviceInfoData)
If value=0
err=GetLastError_()
If err=#ERROR_NO_MORE_ITEMS
out.s+"No more Data is available." +#CRLF$
EndIf
Break
EndIf
hKeyDevice=SetupDiOpenDevRegKey_(hDeviceInfoSet,@DeviceInfoData,#DICS_FLAG_GLOBAL,@HwProfile,#DIREG_DEV,#KEY_QUERY_VALUE)
PortName=Space(128)
lpValueName.s="portname"
lpcbData.l=Len(lpValueName)
RegQueryValueEx_(hKeyDevice,@lpValueName,0,0,@PortName,@lpcbData)
If Left(PortName,3)="COM"
AddElement(ComArray())
ComArray()\ComPort=PortName
out.s+ PortName +#CRLF$
EndIf
RegCloseKey_(hKeyDevice)
DevCount+1
ForEver
If hDeviceInfoSet
SetupDiDestroyDeviceInfoList_(hDeviceInfoSet)
hDeviceInfoSet=0
EndIf
FirstElement(ComArray())
Repeat
out.s+ "Found : "+ComArray()\ComPort +#CRLF$
out1.s+ComArray()\ComPort+":"
AddElement(comports())
Comports()=ComArray()\ComPort+":"
;Debug Comports()
Until NextElement(ComArray())=0
EndIf
EndIf
EndIf
EndIf
EndIf
ProcedureReturn out1.s
EndProcedure
EnumComPorts()
Enumeration
#Window_0
#Combo_0
#Button_0
#Button_1
#Button_2
#Text_0
EndEnumeration
If OpenWindow(#Window_0, 216, 0, 380, 159, "Portauswahl", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
If CreateGadgetList(WindowID(#Window_0))
ComboBoxGadget(#Combo_0, 10, 30, 130, 200, #PB_ComboBox_UpperCase)
ButtonGadget(#Button_0, 240, 30, 90, 20, "ok")
ButtonGadget(#Button_1, 240, 60, 90, 20, "ko")
ButtonGadget(#Button_2, 240, 90, 90, 20, "¿?")
TextGadget(#Text_0, 10, 10, 190, 20, "Wähle den Port")
EndIf
EndIf
ForEach Comports()
AddGadgetItem(#Combo_0,-1,Comports())
Next
SetGadgetState(#Combo_0,0)
Repeat
Event = WaitWindowEvent()
WindowID = EventWindow()
GadgetID = EventGadget()
EventType = EventType()
If Event = #PB_Event_Gadget
If GadgetID = #Combo_0
ElseIf GadgetID = #Button_0
SetGadgetText(#TExt_0,"Na gut ..meinetwegen "+GetGadgetText(#Combo_0))
DisableGadget(#Button_0,1)
Delay(1000)
DisableGadget(#Button_0,0)
SetGadgetText(#TExt_0,"Wähle den Port")
ElseIf GadgetID = #Button_1
End
ElseIf GadgetID = #Button_2
MessageRequester("AHA","Das Zeichen ¿ erhälst Du, wenn Du ALT drückst und dann 0191 eingibst",#MB_ICONEXCLAMATION)
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
End