What Is Difference Between Regasm.Exe and Regsvr32? How to Generate a Tlb File Using Regsvr32

What is difference between RegAsm.exe and regsvr32? How to generate a tlb file using regsvr32?

regsvr32 will load the library and try to call the DllRegisterServer() from that library. It doesn't care what DllRegisterServer() actually does - it just calls that function and checks the returned value. You use it to register COM servers in unmanaged DLLs. It can't generate a .tlb file.

regasm will register a COM-exposed .NET assembly as a COM server. You use it for .NET assemblies. It can generate a .tlb file given the assembly only - it inspects the type infromation stored in the assembly and includes the COM-exposed entities into the type library.

C# COM DLL: do I use Regasm, or Regsvr32?

You need to use regasm.exe to register both the 32 bit and 64 bit interfaces I believe you need to run each of the regasm.exe's in:

C:\Windows\Microsoft.NET\Framework\v2.0.50727

and

C:\Windows\Microsoft.NET\Framework64\v2.0.50727

So... in your case you need to run the regasm.exe in the Framework64\v2.0.50727 folder.

Here's an example we use to register a COM interop DLL for one of our legacy ASP apps:

regasm.exe Hosting.DeviceManager.Power.dll /register /codebase /tlb

Registration with regasm and regsvcs

This is a timed-out response for the question. but let me explain the differences I am aware of.

In order to understand this, you'd have to conjure up the differences between a COM and a COM+ Application.

Register your types as COM - Creates object on demand everytime a code tries to initialize the object

Register your types as COM+ application - Creates object, supports object pooling, supports transactions, supports enhanced Windows security and more.

To understand pooling, I am borrowing a response from http://www.tek-tips.com/viewthread.cfm?qid=116249

COM+'s main method of adding scalability and performance is done through object pooling. Unfortunately, this requires a free-threaded component, which is something VB6 cannot do. But... .NET (any language) and C++ can.

What object pooling does is you tell MTS/COM+ to create a pool of available objects, from a minimum that gets created when COM+ starts, to some maximum (which I don't know if it's a hard maximum, or if it's flexible). What pooling does for you is provide a caller with a pre-initialized object. This is much faster than waiting for an object to be created (especially over a network). The caller connects to the object, makes method calls, and disconnects. The object then goes back into the pool.

It does require a fundamental change in program architecture. Before COM+, everyone would open a connection to a database and leave it open for the duration of the application. This was OK when the user population was <100, as the load on the server was managable (each connection takes up RAM). But for large populations or unknown quantities of users (e.g. users from the Internet), the database server gets overloaded quickly. Someone realized that each transactional user was actually doing real work a small percentage of the time -- the rest of the time they were idle.

So your programs must make a connection, make a request, get the results, and then disconnect (this also applies to non-database objects). This also implies that the application be stateless (program state is not maintained between requests). Because... the object that you're currently using belonged to someone else 200 milliseconds ago. And when you get through using the object, another user will be using it after you. So the objects cannot keep any information around -- they must be code only.

regasm - Registers a .net assembly types as COM. What this means is the regasm picks the publicly exposed types of your .Net assembly and then writes appropriate registry entries at HKCR....; (which is the way regsvr32 works).

  • regasm can generate a tlb file for you (just like tlbexp.exe)
  • regasm can codebase your .Net assembly. That is if you dont have your .Net assembly in the GAC, then you can codebase the COM to the file location where the .Net assembly is present. And from here the COM Marshaller will pick the execute the assembly with CLR.
  • regasm allows you to create a .reg file by double clicking which you can update the registry entries. you have to make sure the .Net assembly is installed to the GAC becase /regfile switch in regasm does not allow you to /codebase (if it does codebase then it is meaningless)

regsvcs - Creates a COM+ Application from a .Net assembly. What this means is the regsvcs picks the publicly exposed types of your .Net assembly and besides writing the appropriate registry entries, it also creates a COM+ application that you can manage via the Componet Services Manager Console (%systemroot%\system32\comexp.msc).

  • regsvcs creates a COM+ application based on the information passed to it from the command line, or based on the information avaialble from the .Net dll.

  • regsvcs allows you to merge your COM+ types to an existing COM+ application. Take a look at comexp.msc to traverse through to understand a COM+ application and and COmponets that a COM+ manages.

If you write a C# class with ComVisible(true) --> The public types of this class (Foo) is ready to be registered with a regasm for COM.

    // Set the COM visibility attribute to true
[ComVisibleAttribute(true)]
public class Foo{....}

If you write a C# class with ComVisible(true), inheriting from System.EnterpriseServices.ServicedComponent (and more setting of course..) --> This class (FooBar) is ready to be registered as a COM+ application.

    // Set the COM visibility attribute to true
[ComVisibleAttribute(true)]
public class FooBar: System.EnterpriseServices.ServicedComponent{.....}

Creating a COM+ application from .Net - You can begin here. Remember COM+ provides advanced transaaction mangement for a COM exposed object.

http://support.microsoft.com/kb/306296
http://my.execpc.com/~gopalan/dotnet/complus/complus.net_accountmanager.html
http://www.codeproject.com/Articles/3845/Creating-COM-Objects-using-EnterpriseServices-in-N

.NET Core 2.1 - How to create COM object and generate *.tlb file

This is now possible due to the work done on .NETCore version 3. As noted in my comment, hosting was the missing piece in earlier .NETCore versions with no substitute for mscoree.dll. Version 3 provides comhost.dll. Related, they also can now support C++/CLI code, ijwhost.dll is the substitute.

You register the component like you did with traditional COM servers, using Regsvr32.dll

Everything you need to know is available in this MSDN page, added a month ago. Do beware that .NETCore 3 is still preview quality right now. And this is Windows-only with no migration path for Linux and macOS, COM is too heavily tied to services that are only available on Windows.

Register 32-bit COM server (and generate TLB) for use with 32-bit and 64-bit clients

From MSDN: Process Interoperability

On 64-bit Windows, a 64-bit process cannot load a 32-bit dynamic-link
library (DLL). Additionally, a 32-bit process cannot load a 64-bit DLL

Your best option seems to compile your component as a 32bit out of process COM server.



Related Topics



Leave a reply



Submit