web analytics

Calling unmanaged DLL functions from C#

Options
@2017-09-14 14:29:49

If all you have is that COM DLL, you can't generate a type library. A type library describes the COM interfaces implemented. But an unmanaged COM DLL merely needs to expose DllGetClassObject. This only gets you an IClassFactory, which lets you create new objects if you kown the correct type up front.

@2017-09-14 14:32:43

To extract type libraries from managed DLLs (e.g., the ones built using C#), Visual Studio includes the tool named Tlbexp.exe to generates a type library that describes the types defined in a common language runtime assembly.

@2017-09-14 14:39:01

When you specify the /tlb option with Regasm.exe (Assembly Registration Tool), Regasm.exe generates and registers a type library describing the types found in the assembly. Regasm.exe places the generated type libraries in the current working directory or the directory specified for the output file. Generating a type library for an assembly that references other assemblies may cause several type libraries to be generated at once. You can use the type library to provide type information to development tools like Visual Studio. You should not use the /tlb option if the assembly you are registering was produced by the Type Library Importer (Tlbimp.exe). You cannot export a type library from an assembly that was imported from a type library. Using the /tlb option has the same effect as using the Type Library Exporter (Tlbexp.exe) and Regasm.exe, with the exception that Tlbexp.exe does not register the type library it produces. If you use the /tlb option to registered a type library, you can use /tlb option with the /unregister option to unregistered the type library. Using the two options together will unregister the type library and interface entries, which can clean the registry considerably.

After registering an assembly using Regasm.exe, you can install it in the global assembly cache so that it can be activated from any COM client. If the assembly is only going to be activated by a single application, you can place it in that application's directory.

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com