views:

175

answers:

2

Hello.

I'm currently developing what is more or less a script that needs to get some data from a VB 6 COM dll. This dll is currently used in a MS Word VBA project, and it exports classes, etc to the VBA code. It is added in the Tools -> References menu in the VBA editor, and I can see it's classes in the object browser of VBA.

From my readings, it is possible to use a VB6 COM library in VB.NET (or at least, it is supposed to be able to.) As it should be possible in VB.NET, and since .NET runs on the CLR, and since IronPython does to, logically, can't i access this ancient DLL from IronPython?

I have tried import clr; clr.AddReferenceToFileAndPath(dllpath) in IronPython, but keep getting 'IOError: file does not exist', which is clearly false.

If anyone can point me to using a VB6 COM object in /any/ .NET language, that would be greatly appreciated.

Thanks!

PS: No, I can't edit / view source of the COM DLL, it's 3rd party proprietary stuff. PPS: Any way I can get the GUID / COM 'name; of the dll?

A: 

You need to generate a Runtime COM Wrapper assembly using the tlbimp tool, and add a reference to that; languages which support .net attributes can do the interoperation explicitly, but even there, autogenerating the wrapper is far simpler.

Inspecting the wrapper assembly in ildasm will show exactly how the conversion has been performed.

Steve Gilham
Thanks! It worked out quite well. I added the referance to the interop assembly in IronPython, and everything `Just Works`! That usually never happens :)
CB
A: 

In any .NET language (in Visual Studio, not sure if IronPython has full language support there, or if it only runs on the CLR with .NET Framework?) you simply go to the Add Reference dialog, select the COM tab, select the library (much like in the VB6/VBA references dialog) and you're basically done. VisualStudio then generates a .NET interop assembly for you that is the middle man to the COM library and you can just use it as if it were a .NET assembly. If IronPython is supported in VisualStudio, that's probably what you should do.

If not, then you need to find out which commandline tool VisualStudio uses to generate the interop assembly (a bit like WSDL.EXE which it uses when you add a web reference), use that tool to manually generate the interop assembly and use that from IronPython as you would do with any other .NET assembly. I don't have any specifics for you right now without checking Google/MSDN, as I only do C# work inside VisualStudio, so I've never actually needed this myself yet.

peSHIr