Re: [Lazarus] devmgmt.msc
El 30/03/2018 a las 22:45, duilio foschi escribió: Hi Jose', doubting a configuration error, I uninstalled Lazarus, then installed it again (current version is 1.8.2). Unfortunately I could not get rid of the error on TLibHandle. Then I found out that this type (TLibHandle) is not declared in system.pas but in rtl/dynlibs.pas Hello, You have a somehow corrupted Lazarus/fpc installation. Ensure that your Lazarus configuration points to the right fpc executable, or start a configuration from scratch using the "--pcp" executable parameter. Something like "Lazarus.exe --pcp C:\Lazarus\CleanConfig" TLibHandle is defined in "sysdlh.inc" which is included by "dynlibh.inc" which is included by "system" unit in Windows platform. Also you get a compilation error in the dwarf support which has been included long time ago, so your Lazarus configuration is pointing to an old fpc 2.2 or something like that. -- -- ___ Lazarus mailing list Lazarus@lists.lazarus-ide.org https://lists.lazarus-ide.org/listinfo/lazarus
Re: [Lazarus] devmgmt.msc
Hi Jose', doubting a configuration error, I uninstalled Lazarus, then installed it again (current version is 1.8.2). Unfortunately I could not get rid of the error on TLibHandle. Then I found out that this type (TLibHandle) is not declared in system.pas but in rtl/dynlibs.pas http://i67.tinypic.com/20ft940.jpg I fixed the problem by adding dynlibs.pas to the project. Unfortunately when I compile the code I get new error messages (see below) in unit lnfodwrf. See http://i68.tinypic.com/116qrdy.jpg Well, I am sure I will fix all problems before or later :) Thank you Peppe lnfodwrf.pp(846,23) Error: Incompatible types: got "" expected "" -- ___ Lazarus mailing list Lazarus@lists.lazarus-ide.org https://lists.lazarus-ide.org/listinfo/lazarus
Re: [Lazarus] devmgmt.msc
Hi Jose', thank you for the code, but 1. I get a number of error messages while compiling the unit with Lazarus 1.6.4 under W7 (see below) 2. I cannot understand how I can get the enumerated COM device names into a TStringList as I need to process the names. Thank you Peppe Compile Project, Target: C:\Users\PCCE88~1.BUF\AppData\Local\Temp\project1.exe: Exit code 1, Errors: 11 udeviceenumwin.pas(83,22) Error: Identifier not found "TLibHandle" udeviceenumwin.pas(83,32) Error: Error in type definition udeviceenumwin.pas(164,23) Error: Operator is not overloaded: "" = "ShortInt" udeviceenumwin.pas(165,88) Error: Incompatible type for arg no. 1: Got "", expected "QWord" udeviceenumwin.pas(166,96) Error: Incompatible type for arg no. 1: Got "", expected "QWord" udeviceenumwin.pas(167,101) Error: Incompatible type for arg no. 1: Got "", expected "QWord" udeviceenumwin.pas(168,97) Error: Incompatible type for arg no. 1: Got "", expected "QWord" udeviceenumwin.pas(169,102) Error: Incompatible type for arg no. 1: Got "", expected "QWord" udeviceenumwin.pas(170,90) Error: Incompatible type for arg no. 1: Got "", expected "QWord" udeviceenumwin.pas(184,26) Error: Operator is not overloaded: "" = "ShortInt" udeviceenumwin.pas(184,65) Error: Incompatible type for arg no. 1: Got "", expected "QWord" 2018-03-29 14:22 GMT+02:00 José Mejuto : > El 28/03/2018 a las 22:48, duilio foschi via Lazarus escribió: >> >> if I run devmgmt.msc on W7 I get this info on screen: >> Is there a Winows API I can call from my Lazarus program and get the same >> info ? >> My aim is to detect which COM number was assigned to the USB device >> "MSP Application UART1" > > > Hello, > > Attached unit will help you to implement a COM port browsing. There is a bit > of extra code as original comes from a bigger unit, and this is an extract. > > > -- > -- ___ Lazarus mailing list Lazarus@lists.lazarus-ide.org https://lists.lazarus-ide.org/listinfo/lazarus
Re: [Lazarus] devmgmt.msc
El 28/03/2018 a las 22:48, duilio foschi via Lazarus escribió: if I run devmgmt.msc on W7 I get this info on screen: Is there a Winows API I can call from my Lazarus program and get the same info ? My aim is to detect which COM number was assigned to the USB device "MSP Application UART1" Hello, Attached unit will help you to implement a COM port browsing. There is a bit of extra code as original comes from a bigger unit, and this is an extract. -- unit udeviceenumwin; {$mode objfpc}{$H+} interface uses Classes, SysUtils; function EnumDevices: integer; implementation uses windows; const WINDOWS_SETUPAPI_NAME='setupapi.dll'; DIGCF_DEFAULT = $0001; DIGCF_PRESENT = $0002; DIGCF_ALLCLASSES = $0004; DIGCF_PROFILE = $0008; DIGCF_DEVICEINTERFACE = $0010; SPDRP_FRIENDLYNAME = $000C; type {$PackRecords C} HDEVINFO = type THANDLE; SP_DEVINFO_DATA = record cbSize: DWORD; ClassGuid: TGUID; DevInst: DWORD;// DEVINST handle Reserved: Pointer; end; PSP_DEVINFO_DATA=^SP_DEVINFO_DATA; SP_DEVICE_INTERFACE_DATA = record cbSize: DWORD; InterfaceClassGuid: TGUID; Flags: DWORD; Reserved: Pointer; end; PSP_DEVICE_INTERFACE_DATA= ^SP_DEVICE_INTERFACE_DATA; SP_DEVICE_INTERFACE_DETAIL_DATA_W = packed record cbSize: DWORD; DevicePath: array [0..0] of WideChar; end; PSP_DEVICE_INTERFACE_DETAIL_DATA_W = ^SP_DEVICE_INTERFACE_DETAIL_DATA_W; // SETUPAPI.DLL TSetupDiGetClassDevs = function (var aGUID: TGUID; aEnumerator: PWideChar; hwndParent: SizeInt; aFlags: DWORD): HDEVINFO; stdcall; TSetupDiEnumDeviceInterfaces = function (DeviceInfoSet: HDEVINFO; DeviceInfoData: PSP_DEVINFO_DATA; var InterfaceClassGuid: TGUID; MemberIndex: DWORD; var DeviceInterfaceData: SP_DEVICE_INTERFACE_DATA): WINBOOL; stdcall; TSetupDiGetDeviceInterfaceDetailW = function (DeviceInfoSet: HDEVINFO; DeviceInterfaceData: PSP_DEVICE_INTERFACE_DATA; DeviceInterfaceDetailData: PSP_DEVICE_INTERFACE_DETAIL_DATA_W; DeviceInterfaceDetailDataSize: DWORD; var RequiredSize: DWORD; DeviceInfoData: PSP_DEVINFO_DATA): WINBOOL; stdcall; TSetupDiDestroyDeviceInfoList = function (DeviceInfoSet: HDEVINFO): WINBOOL; stdcall; TSetupDiGetDeviceRegistryPropertyA = function (DeviceInfoSet: HDEVINFO; DeviceInfoData: PSP_DEVINFO_DATA; PropertyID: DWORD; PropertyRegDataType: PDWORD; PropertyBuffer: PBYTE; PropertyBufferSize: DWORD; RequiredSize: PDWORD): WINBOOL; stdcall; TSetupDiEnumDeviceInfo = function (DeviceInfoSet: HDEVINFO; MemberIndex: DWORD; var DeviceInterfaceData: SP_DEVICE_INTERFACE_DATA): WINBOOL; stdcall; type TDLLSetupAPIEntriesRecord=record SetupDiGetClassDevs: TSetupDiGetClassDevs; SetupDiEnumDeviceInterfaces: TSetupDiEnumDeviceInterfaces; SetupDiGetDeviceInterfaceDetailW: TSetupDiGetDeviceInterfaceDetailW; SetupDiDestroyDeviceInfoList: TSetupDiDestroyDeviceInfoList; SetupDiGetDeviceRegistryPropertyA: TSetupDiGetDeviceRegistryPropertyA; SetupDiEnumDeviceInfo: TSetupDiEnumDeviceInfo; end; var DLLSetupAPIHandle: TLibHandle; DLLInitializedFlag: Boolean=false; DLLInitializedSuccess: Boolean=false; DLLSetupAPIFunctions: TDLLSetupAPIEntriesRecord; function InitializeLibraries: Boolean; forward; procedure DEBUG_OUTPUT(msg: string); begin writeln(msg); end; function EnumDevices(): integer; var lGUID: TGUID='{4d36e978-e325-11ce-bfc1-08002be10318}'; // COM PORTS and LPT lDeviceInfoList: HDEVINFO; lDeviceInfo: SP_DEVICE_INTERFACE_DATA; lMemberIndex: integer; lStopEnumeration: Boolean=false; lIndex: integer; lFriendlyName: array [0..511] of char; begin if not InitializeLibraries then exit(1); ldeviceInfoList := DLLSetupAPIFunctions.SetupDiGetClassDevs(lGUID, nil, 0, DIGCF_PRESENT or DIGCF_DEVICEINTERFACE); if lDeviceInfoList=INVALID_HANDLE_VALUE then begin exit(2); end; lDeviceInfo.cbSize:=SizeOf(lDeviceInfo); lMemberIndex:=0; while true do begin if not DLLSetupAPIFunctions.SetupDiEnumDeviceInterfaces(ldeviceInfoList, nil, lGUID, lMemberIndex, lDeviceInfo) then begin // Browse finished lStopEnumeration:=true; break; end; lIndex:=0; while true do begin if DLLSetupAPIFunctions.SetupDiEnumDeviceInfo(lDeviceInfoList,lIndex,lDeviceInfo)=FALSE then begin break; end; if DLLSetupAPIFunctions.SetupDiGetDeviceRegistryPropertyA(lDeviceInfoList,@lDeviceInfo,SPDRP_FRIENDLYNAME,nil,@lFriendlyName[0],sizeof(lFriendlyName)-1,nil) then begin DEBUG_OUTPUT(lFriendlyName); end; inc(lIndex); end; if lStopEnumeration then break; inc(lMemberIndex); end;
[Lazarus] devmgmt.msc
if I run devmgmt.msc on W7 I get this info on screen: http://i66.tinypic.com/2lucq4n.jpg Is there a Winows API I can call from my Lazarus program and get the same info ? My aim is to detect which COM number was assigned to the USB device "MSP Application UART1" Thank you Peppe -- ___ Lazarus mailing list Lazarus@lists.lazarus-ide.org https://lists.lazarus-ide.org/listinfo/lazarus