Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: How to prevent TLibImp.exe from using registry for resolving references


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Apr 21, 2016 3:39 AM Last Post By: Emil Konring Ol... Threads: [ Previous | Next ]
Emil Konring Ol...

Posts: 4
Registered: 12/1/13
How to prevent TLibImp.exe from using registry for resolving references  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 25, 2016 7:12 AM
We use the TLibImp.exe tool to build interface .pas files from .tlb files to get access to other C# based COM dll's. The runtime system is manifest driven, enabling us to have different versions installed at the same time without problems.
TLibImp works fine as long as there are no references between the .tlb files.
If A.tlb references COM elements in Common.tlb, TLibImp.exe is also capable of generating interface .pas files, but will only succeed, if done as administrator and with the side effect of having globally registered the COM elements of Common.tlb (in registry), which is not acceptable in our buildserver context.

TLibImp (Version 12.16581, Delphi 10 Seattle Version 23.0.20618.2753) is called with this command-line:
TLibImp.exe -P -Ha- -Hs- -Hr- -R- -Pt+ -Dxxx\yyy -FtA.pas A.tlb

We assume, that the -Hr- switch should prevent TLibImp from registering in registry, and that is how it is, except when referencing other .tlb's

The error message received on our buildserver goes like this:
Library not registered.
An error occured while referencing a user defined type. This may be caused by a missing or unregistered type library

Is there any way to prevent TLibImp from using global registry to resolve references to other .tlb's ?

Regards
Emil
Remy Lebeau (Te...


Posts: 9,448
Registered: 12/23/01
Re: How to prevent TLibImp.exe from using registry for resolving references  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 25, 2016 11:37 AM   in response to: Emil Konring Ol... in response to: Emil Konring Ol...
Emil wrote:

Is there any way to prevent TLibImp from using global
registry to resolve references to other .tlb's ?

you might try creating a "Registration-Free COM" manifest for TImpLib.exe,
and put your TLB details in that manifest as needed.

https://msdn.microsoft.com/en-us/library/ms973913.aspx

http://blogs.msdn.com/b/junfeng/archive/2006/04/20/579748.aspx

You can put the manifest XML into a separate TImpLib.exe.manifest text file
in the same folder as TImpLib.exe.

--
Remy Lebeau (TeamB)
Emil Konring Ol...

Posts: 4
Registered: 12/1/13
How to prevent TLibImp.exe from using registry for resolving references  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 1, 2016 1:26 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

you might try creating a "Registration-Free COM" manifest for TImpLib.exe,
and put your TLB details in that manifest as needed.

You can put the manifest XML into a separate TImpLib.exe.manifest text file
in the same folder as TImpLib.exe.

Thank you, Remy, for helping us to solve the problem.

Registration free COM is widely used within our applications, and since TLibImp has no internal manifest, there is a possibility (as suggested by you), that it might respond to an external manifest.
We tried this, but unfortunately without success. It seems, that TLibImp does not take into account the external manifest info, when trying to resolve references.

In case we used an incorrect external manifest or made other mistakes, I added some details info below.

/Emil

Details:
TLibImp.exe was copied to the directory containing the .tlb files
A TLibImp.exe.manifest file was added in the same directory and with the following content
(Common being the .dll to resolve external references from the .tlb file currently processed):

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly
manifestVersion="1.0"
xmlns="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity
type="win32"
name="TLibImp"
version="1.0.0.0"
/>

<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Common"
version="1.0.0.0"
publicKeyToken="" />
</dependentAssembly>
</dependency>

</asmv1:assembly>
Remy Lebeau (Te...


Posts: 9,448
Registered: 12/23/01
Re: How to prevent TLibImp.exe from using registry for resolving references  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 1, 2016 10:20 AM   in response to: Emil Konring Ol... in response to: Emil Konring Ol...
Emil wrote:

TLibImp.exe was copied to the directory containing the .tlb files
A TLibImp.exe.manifest file was added in the same directory and with
the following content
(Common being the .dll to resolve external references from the .tlb
file currently processed):

That manifest is simply declaring a dependancy on an external Common.dll
v1.0.0.0 file. What does the manifest for THAT file look like? Does it
declare any Registration-Free COM entries for the TLB content?

--
Remy Lebeau (TeamB)
Emil Konring Ol...

Posts: 4
Registered: 12/1/13
How to prevent TLibImp.exe from using registry for resolving references  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 20, 2016 4:31 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Sorry, it took me a while to find time to produce a simple example to illustrate the problem..
And now I realize, that it seems I cannot append a file to my reply.

Please let me know the best way to share a zip file with you ?

/Emil
Emil Konring Ol...

Posts: 4
Registered: 12/1/13
How to prevent TLibImp.exe from using registry for resolving references  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 21, 2016 3:39 AM   in response to: Emil Konring Ol... in response to: Emil Konring Ol...
We found a way of sharing the sample project with you, please follow the link below:
https://github.com/pars87/COMSideBySide/archive/master.zip

In the zip'ed C++/C# test project found behind the link (ComUltimateTemplate.sln), ScInteropTest.tlb contains references to elements in CommonInterop.tlb.
When importing ScInteropTest.tlb with the 'no_registry' option excluded (stdafx.h), the import (without administrators rights) will fail for very much the same reasons, that TLibImp fails.
When the 'no_registry' option is included, the import and the test will succeed.

Unfortunately TLibImp does not support a 'no_registry' option, and this is our real problem.
The assumption is, that with properly designed side-by-side manifests, TLibImp (and presumeably the C++/C# project) could be made to successfully import the dependent .tlb files witout administrators rights.
We made quite some tests with different manifest layouts, but we are not experts in this area and had no succes.

The included ImportScInterop.cmd file activates TLibImp.exe to produce a .pas file from the dependent .tlb files.
The question is, if it's possible by manipulating the manifest files (CommonInterop.manifest, CommonInterop.Interop.Cpp.Test.dll.manifest and TLibImp.exe.manifest) to make this .cmd file pass without administrators rights.

Any help would be appreciated

Best regards
/Emil
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02