我有一个 VB 6.0 dll,它有如下方法:
Public Function PrintDemo() As Integer
PrintDemo = 10
End Function
dll 已在我的机器上注册。我需要将这个 dll 动态加载到 C# 中。以下是我在 C# 中尝试的方式:
Type obj = Type.GetTypeFromProgID("Project1.Class1");
object ins = Activator.CreateInstance(obj);
var method1 = obj.InvokeMember("PrintDemo", BindingFlags.InvokeMethod, null, obj, null);
Console.WriteLine(method1);
dll 已成功加载,但我无法调用它。
有人可以帮我解决这个问题吗?
最佳答案
努力改变
obj.InvokeMember("PrintDemo", BindingFlags.InvokeMethod, null, obj, null);
// To...
obj.InvokeMember("PrintDemo", BindingFlags.InvokeMethod, null, ins, null);
我相信您应该发送实例“ins”作为目标而不是类型。 否则就没有理由创建一个实例。
我已经有很长时间没有使用反射了......
关于c# - 如何在 C# 中动态加载 VB 6.0 dll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20569278/