COM-Client lazarus / 67-Windows ---------------------------------------------------------------------- kupferstecher · 2023-11-22 17:43 Hi, is it possible to create a COM-Client with Freepascal under Windows? I think it should as Freepascal supports COM-Interfaces, but I didn't find any information on how to connect to a COM-Server. I only found some OLE and ActiveX examples, but I guess thats something else. See below C++ code snippet, I want to achive the same with freepascal. As far as I understand the #import directive gathers the type information of the COM object, so for a successful compilation the compiler already has to retrieve type information. Is it possible or is there a workaround to gather the type information in other means and to translate it to Pascal 'headers'? Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #import "libid:BD962F0D-A990-[...]" no_namespace   CoCreateInstance(__uuidof(NNNNDeviceList), [...]  Thanks! Edit: Removed brand name. ---------------------------------------------------------------------- marcov · 2023-11-22 18:22 The FPC type importer is called importtl. ---------------------------------------------------------------------- kupferstecher · 2023-11-22 20:10 Thanks, I'll have a look! And then perhaps ask further ---------------------------------------------------------------------- marcov · 2023-11-22 20:52 There are some com related bug reports in the trackers that have good examples. ---------------------------------------------------------------------- avra · 2023-11-22 20:54 Quote from: kupferstecher on November 22, 2023, 06:43:23 pmis it possible to create a COM-Client with Freepascal under Windows?Of course it is. OPC DA is based on COM, so you can also take a look at it. https://sourceforge.net/projects/myopcclient/ https://github.com/seryal/OPCComponent ---------------------------------------------------------------------- kupferstecher · 2023-11-22 22:09 Importtl worked, I used the following command line: Path\importtl.exe "Path\NNNNCom.exe" This created a Pascal unit containing all the types and so on, so I can include the unit in the uses of my project. Further questions: 1. I'm not so clear now, how the Com-Server, that I wan't to communicate with, is started. Should it already run when I try to "connect" with the client, or is there an automatic starting mechanism when I instantiate a COM object? 2. What would the CoCreateInstance() (c++) equivalent be in Pascal? I found the CreateComObject() function in avra's link, could it be that? @avra, thanks for the link, I have a look, but seems to be a bigger project @marcov: Also thanks! About the bug reports, what keywords would you search for, I didn't find anything related so far. Edit: Removed brand name. ---------------------------------------------------------------------- marcov · 2023-11-22 22:13 1.  Afaik the dll should be registered together with the GUID using the regsvr(32) binary. (admin box in modern windows afaik) Of course there is always 32-bit vs 64-bit to look out for. 2.  Code: [Select]   function CreateComObject(const ClassID : TGUID) : IUnknown;      begin        OleCheck(CoCreateInstance(ClassID,nil,CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER,IUnknown,result));      end; So basically it is a simple wrapper, olecheck changes COM related return values into exceptions I think. bugreports: I don't know if this all surived the mantis -> gitlab changesover, but the old bugreports were tagged as "COM". I think servers are harder than clients though. ---------------------------------------------------------------------- kupferstecher · 2023-11-22 22:27 Ok, great. 1. OK, I make some tests first. 2. Understood! Thanks so far! ---------------------------------------------------------------------- kupferstecher · 2023-11-23 20:09 Me, again.. After some tests I'm still stuck with an error, EOleSysError: Class not registered. It occurs in the moment the interface is created (Its the first line of code). Compilation works fine. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i DeviceList:= CreateComObject(IID_INNNNDeviceList) as INNNNDeviceList;I wonder if I have to load the library before something within the library is refered to. The error is the same for 64bit and 32bit (crosscompiled on 64bit Lazarus) applications. Also I tested the c++ example code (snippet in post 1) with Visual Studio and that works. So the automatic loading of the COM server obviously can work. The registry stuff was probably done by the installer of the software and driver package of the device that I want to connect with. I also tried to compile the c++ example code with gcc, but it doesn't support the syntax #import "libid:... Maybe there is some special compiler magic involved with this command? Anyone any idea how to get it working under Lazarus? Do I have to load the executable somehow? As far as I understand the server is a exe and not a dll. Thanks! Here the code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit uCOMClient;{$mode ObjFPC}{$H+} interface uses  Classes, SysUtils,  ComObj,  NNNNCOMLib_1_12_TLB; Procedure GetDevices; var  DeviceList: INNNNDeviceList; implementation Procedure GetDevices;begin   DeviceList:= CreateComObject(IID_INNNNDeviceList) as INNNNDeviceList; //EOleSysError   writeln('Available Devices: ',DeviceList.Count);   DeviceList:= nil; //automatically releasedend; end.  Edit: Removed brand name. ---------------------------------------------------------------------- marcov · 2023-11-23 20:59 Afaik coinitialize is done by the comobj unit entry code, so this should simply work. ---------------------------------------------------------------------- kupferstecher · 2023-11-23 21:05 Could i do that manually for testing? ---------------------------------------------------------------------- kupferstecher · 2023-11-23 21:22 Or is there any way to see what requests the program is sending to the OS? Then perhaps it would be possible to compare what is different to the c++ program. ---------------------------------------------------------------------- kupferstecher · 2023-11-23 21:36 It seems to work now! I took the wrong GUID, should be CLASS_NNNNDeviceList instead of IID_INNNNDeviceList. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i DeviceList:= CreateComObject(CLASS_NNNNDeviceList) as INNNNDeviceList; Edit: Removed brand name.