tags:

views:

87

answers:

2

I have been given an old dll and the assignment of accessing it through C# .NET 3.5. I believe the dll was originally built with VB6, but am not positive. There is no documentation or source for the dll aside from an example for how to use the it in VB6. I have been able to succesfully access it through VB.NET 3.5. Example code for accessing looks like this:

myLib = CreateObject("MyLib.api")
myConnection = myLib.CreateObject("NameOfConnectionObject")
myConnection.do_something("abc")

There are several different objects that are created from the library and all of those objects have different methods. I tried using different dll reading tools, but all the export methods show up as garbage. I also tried importing the dll in visual studio, but I get an error stating the dll is not accessible and/or not a COM object or assembly. So, I only know about the methods from the old documentation which is sparse.

Any ideas on how to access in C# and/or find out more about this mystery dll?

Thanks!

+1  A: 

Have you tried reflector ? http://www.red-gate.com/products/reflector/ ?

EDIT: reflector doesnt work with non .net assemblies, and this is VB6, so this is not a viable solution

Miau
Reflector decompiles .Net not VB6. It seems unlikely that this mystery DLL is a .Net DLL.
MarkJ
oops, completely missread the 6 part of vb6
Miau
+3  A: 

The code snippet is using late binding, it is definitely a COM server. If it was written in VB6 then it should also have a type library. The odds are low if you can't add a reference to it from Visual Studio but I've seen a few cases where it failed but Tlbimp.exe had no problem. Run it from the Visual Studio Command Prompt. You can also run OleView.exe and use File + View Typelib to look at the type library.

If these attempts fail then you're done, you can't reverse engineer this COM component without documentation. Which, frankly, is fairly risky anyway. If the original supplier of this COM component is out of business then there ought to be at least a programmer that still remembers working on this. He might be reading SO but he can't find you until you drop some names.

Hans Passant
All these are great ideas. you SHOULD be able to add a reference to it in VS, then use the object browser to checkout the available objects and properties/methods. Also just because the existing code samples show using the library LATEBOUND doesn't necessarily mean you have to. Using the Object browse from VS should let you instantiate objects and get nice intellisense from just about any VB6 authored COM library.
drventure
+1 Try these ideas first. If they fail I would try one more thing before going to reverse engineerin or rewriting. Write a new VB6 component as a bridge, I.e. a thin wrapper around the mystery dll. You shouldn't have any problems calling your new wrapper from C#. If necessary you could alter the method signatures etc. to resolve any problems that do arise.
MarkJ
Thanks for the suggestions... none have worked. I did some more digging around and found that the object instantiated is not from the dll I had assumed, but from an old powerbuilder dll. I assume that the powerbuilder dll passes through to the dll I was originally given.
derivation
Agreed, abandon all hope if this was Powerbuilder. Late binding is your lot. Its okayish in VB.NET and C# 4.0 with the dynamic keyword.
Hans Passant