简体   繁体   English

如何从C#访问和了解旧的dll

[英]How to access and understand old dll from C#

I have been given an old dll and the assignment of accessing it through C# .NET 3.5. 我得到了一个旧的dll,并获得了通过C#.NET 3.5访问它的任务。 I believe the dll was originally built with VB6, but am not positive. 我相信该dll最初是用VB6构建的,但不是肯定的。 There is no documentation or source for the dll aside from an example for how to use the it in VB6. 除了如何在VB6中使用dll的示例外,没有dll的任何文档或资料来源。 I have been able to succesfully access it through VB.NET 3.5. 我已经能够通过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. 我尝试使用其他dll读取工具,但所有导出方法都显示为垃圾。 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. 我也尝试在Visual Studio中导入dll,但出现错误,指出该dll无法访问和/或不是COM对象或程序集。 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? 关于如何在C#中访问和/或了解有关此神秘dll的更多信息?

Thanks! 谢谢!

The code snippet is using late binding, it is definitely a COM server. 该代码段使用的是后期绑定,它绝对是COM服务器。 If it was written in VB6 then it should also have a type library. 如果它是用VB6编写的,则它还应该具有类型库。 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. 如果您无法从Visual Studio中添加对它的引用,则可能性很小,但是我已经看到了几次失败的案例,但是Tlbimp.exe没问题。 Run it from the Visual Studio Command Prompt. 从Visual Studio命令提示符运行它。 You can also run OleView.exe and use File + View Typelib to look at the type library. 您也可以运行OleView.exe并使用File + View Typelib查看类型库。

If these attempts fail then you're done, you can't reverse engineer this COM component without documentation. 如果这些尝试失败了,那么您就完成了,如果没有文档,您将无法对该COM组件进行反向工程。 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. 如果该COM组件的原始供应商停运了,那么至少应该有一个程序员仍然记得要从事此工作。 He might be reading SO but he can't find you until you drop some names. 他可能正在读SO,但是直到您写下一些名字他才能找到您。

Have you tried reflector ? 你试过反射器了吗? http://www.red-gate.com/products/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 编辑:反射器不适用于非.net程序集,这是VB6,所以这不是可行的解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM