Destination IUnknown

Mostly on .NET, Java, Blogosphere, software development and techie stuff by Victor Hadianto

Friday, 27 June 2008

Manually creating Interop dll using tlbimp.exe

Visual Studio .Net automatically creates Interop dll when you reference the COM dll in your project. This is all nice and behaves as expected, but at times you may want to create the Interop dll manually.

Tlbimp.exe is the tool to use. However, strange as it may seems, by default it doesn't do what Visual Studio does. How interesting ...

Visual Studio .Net by default add "Interop." at the beginning of the generated Interop dll and set the namespace as the name of the dll sans the ".dll".

For example, if the dll is called MyCOM.dll. Visual Studio generates: Interop.MyCOM.dll and creates the Interop dll under MyCOM namespace.

To achieve the same effect using tlbimp, you need to use both the /out and /namespace flag. For example:

tlbimp /out:Interop.MyCOM.dll /namespace:MyCOM MyCOM.dll

Sorted.

Labels: ,

Wednesday, 5 March 2008

LoaderLock was detected

Blimey … what was that? This kind of exception, that only happens during debugging, confuses developers. Googling about the problem shows that Microsoft at times gives pointless answer. Some blame iTunes about this problem ;)

Rather than following the advice to turn this rather useful check in VS 2005, the most probable causes of this problem are:

1) An unmanaged dll calls a managed dll on its DLLMain or
2) Not marshalling your call back to the main UI thread.

Vivek wrote a bit more about this problem here.

Labels: ,