Mark Williams 14 Posted July 26, 2020 I have converted an existing 64bit app into an out of process com server by adding an automation object, but now I am completely lost as to how to register it and how to import the type library. RegSvr32 fails with "DLLRegisterServer" not found. I have tried running with "/regserver" switch. In non admin mode it crashes and in admin mode it asks if you want to make changes etc, but then doesn't seem to run the app (no sign of it in processes) although no error appears. I tried using tlibimp.exe to import the type library, but that reported an error loading the type library. I assume that is because there is no type library to import on account of the failure to register the server in the first place! Share this post Link to post
Anders Melander 1783 Posted July 26, 2020 Don't use regsvr32 - that's for in-process servers. You can't use task manager to verify that you server is being executed (it terminates as soon as it finishes registering) but you should be able to verify if your server has been registered by looking in the registry. If you don't know where to look then you need to read some docs on msdn. COM is a nightmare if you don't understand how it works. Anyhow, try this: Run Delphi as as administrator. Enter /regserver in Run|Parameters Place a breakpoint in TComServer.Initialize (in the System.Win.ComServ unit). Run your server in the debugger. You should now be able to trace through TComServer.UpdateRegistry and verify that it ends up registering your type library and your COM classes (probably via TComObjectFactory.UpdateRegistry). 1 Share this post Link to post
Arnaud Bouchez 407 Posted July 27, 2020 Note that 32-bit and 64-bit COM servers are registered separated, IIRC. To communicate between apps, I would rather use a regular REST server. Our little mORMot can re-use an interface to define the service, just like with COM. Check https://medium.com/@step.bester/web-apis-with-mormot-891c0ecd3950 Share this post Link to post
Mark Williams 14 Posted July 27, 2020 12 hours ago, Anders Melander said: Run Delphi as as administrator. Enter /regserver in Run|Parameters Thanks that worked. I originally just ran my app from a shortcut with the /regserver parameter, but that didn't seem to work ie no entries in the register. Running it through the IDE with /regserver did the job. However, how do I import this type library into Delphi? As I mention above it is 64 bit and therefore you can't do it via the IDE so I have tried with tlibimp.exe via a cmd prompt. It still report an error loading the type library. Share this post Link to post
Mark Williams 14 Posted July 27, 2020 1 hour ago, Arnaud Bouchez said: Note that 32-bit and 64-bit COM servers are registered separated, IIRC. To communicate between apps, I would rather use a regular REST server. Our little mORMot can re-use an interface to define the service, just like with COM. Check https://medium.com/@step.bester/web-apis-with-mormot-891c0ecd3950 Thanks for the tip. I will look into it if I have problems via com. My out of process server is only intended for (and will only work with) a Word Add-In that I am developing. So I may run into problems with 32 bit via 64 bit if users are running 32 bit word. So that's something I'm going to have to overcome. Share this post Link to post
Arnaud Bouchez 407 Posted July 27, 2020 So a REST server won't work since you need a COM object as Word Add-In. Share this post Link to post
Mark Williams 14 Posted July 27, 2020 24 minutes ago, Arnaud Bouchez said: So a REST server won't work since you need a COM object as Word Add-In. I guess so. Share this post Link to post
Anders Melander 1783 Posted July 27, 2020 3 hours ago, Arnaud Bouchez said: Note that 32-bit and 64-bit COM servers are registered separated, IIRC. Yes, the registration is stored in different places in the registry but that's really a Windows implementation detail. For out-of-process COM servers a 32-bit client have no problems connecting to a 64-bit server and vice versa. Here's a nice summary: https://mariusbancila.ro/blog/2010/11/04/32-bit-and-64-bit-com-servers/ For in-process servers (i.e. basically just a DLL) the bitness must match. 4 hours ago, Arnaud Bouchez said: To communicate between apps, I would rather use a regular REST server. https://en.wikipedia.org/wiki/Law_of_the_instrument Share this post Link to post
Mark Williams 14 Posted July 27, 2020 I have worked out how to import the type library for a 64bit out of process server using tlibimp.exe. I was originally pointing tlibimp at the exe file and hoping it would magically produce something for me. It needs to be pointed at the tlb file. Share this post Link to post
Mark Williams 14 Posted July 27, 2020 (edited) Apologies duplicate post. Edited July 27, 2020 by Mark Williams Posted in error Share this post Link to post
Mark Williams 14 Posted July 27, 2020 13 minutes ago, Anders Melander said: For in-process servers (i.e. basically just a DLL) the bitness must match. There is a registry hack to get around this: https://www.codeproject.com/questions/267099/how-do-i-use-32-bit-dll-in-64-bit-app Share this post Link to post
Anders Melander 1783 Posted July 27, 2020 1 minute ago, Mark Williams said: There is a registry hack to get around this ...and you can juggle chainsaws. 1 Share this post Link to post
Anders Melander 1783 Posted July 27, 2020 20 minutes ago, Mark Williams said: I have worked out how to import the type library for a 64bit out of process server using tlibimp.exe. The /regserver should register the type library embedded in the application (via TComServer.UpdateRegistry). Didn't it do that? Share this post Link to post
Mark Williams 14 Posted July 27, 2020 24 minutes ago, Anders Melander said: The /regserver should register the type library embedded in the application (via TComServer.UpdateRegistry). Didn't it do that? Yes. But it didn't create the Delphi wrapper that you get via the type library functions in the IDE Share this post Link to post
Anders Melander 1783 Posted July 27, 2020 19 minutes ago, Mark Williams said: Yes. But it didn't create the Delphi wrapper that you get via the type library functions in the IDE You can create that from within the IDE: Component | Import Component | Import a Type Library 1 Share this post Link to post
Mark Williams 14 Posted July 27, 2020 21 minutes ago, Anders Melander said: You can create that from within the IDE: Component | Import Component | Import a Type Library OK. That's good to know. Thanks. Share this post Link to post