从 COM 可调用包装器返回错误的对象

发布于 2024-08-03 04:22:30 字数 550 浏览 2 评论 0原文

我刚刚对 Powerpoint 中从 VBA 调用的 dll 进行了更新。所有开发都很顺利,但是当我尝试在另一台用户计算机上部署时,我遇到了一个问题,我不知道如何调试。

发生的情况是,当在 VBA 中创建 .Net 对象时,返回的引用指向错误的对象,因此下一行失败,并显示方法未找到。

Dim myObj As Foo.Bar

Public Sub RefreshData()

//'instantiate object
Set myObj = New Foo.Bar   
//'call a method
myObj.HelloWorld

最后一行失败,并显示运行时错误 '438' 对象不支持此属性或方法,这是由于 myObj 的类型为“Wrong.Type”而不是“Foo.酒吧”。

“Wrong.Type”也在程序集中,所以我认为类型库出了问题,但我尝试重新生成(使用 regasm /codebase /tlb MyLib.dll),但这没有帮助。

我不知道如何进一步诊断。希望有人可以列出一些如何诊断此类问题的步骤?

I have just made an update to a dll that is called from VBA within Powerpoint. All development went fine, but when I tried to deploy on another users machine I get a problem that I have no idea how to debug.

What happens is that when the .Net object is created in the VBA, the reference that is returned is to the wrong object, so the next line fails with method not found.

Dim myObj As Foo.Bar

Public Sub RefreshData()

//'instantiate object
Set myObj = New Foo.Bar   
//'call a method
myObj.HelloWorld

The last line fails with Run-time error '438' Object doesn't support this property or method which is caused by the fact that myObj is somehow of type "Wrong.Type" instead of "Foo.Bar".

"Wrong.Type" is also in the assembly, so I assume something is going wrong with the type library, but I have tried regenerating (using regasm /codebase /tlb MyLib.dll), and this hasn't helped.

I don't know how to diagnose this any further. Hopefully someone out there can list some steps on how to diagnose this sort of problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绅士风度i 2024-08-10 04:22:30

这可能是自动生成的 GUID(类、接口、类型库)的问题 - 当您更改 DLL 时,GUID 也会更改。由于旧的 TLB 使用旧的 GUID,通过引用它,您将这些旧的 GUID 与类型名称相关联,因此代码无法使用新的 GUID。我遇到的大多数 VB(6 和 .NET)代码都存在此问题,因此如果您的 DLL 是用 VB 编写的,则可能就是这样(并且您的工作支持此理论)。

如果这是问题所在,一般的解决方案是显式设置 GUID,如果您有很多类型,这会有点烦人,因为您应该随着版本的更改而更改 GUID,并且您必须手动进行。

It might the problem of automatically generated GUIDs (class, interface, type library) - when you changed the DLL, GUIDs changed. Since the old TLB used old GUIDs, by referencing it, you associated those old GUIDs with type names, so the code failed to work with the new GUIDs. Most VB (6 and .NET) code I encountered has this problem, so if your DLL is written in VB, it's probably it (and your work around supports this theory).

If that is the problem, a general solution is to set GUIDs explicitly, which is a little annoying if you have a lot of types, since you're supposed to change GUIDs as your version(s) change, and you'll have to do it manually.

初见你 2024-08-10 04:22:30

在这种情况下,删除对 tlb 文件的引用,然后再次添加它可以解决问题。

不幸的是,我从未找到通用的解决方案或行为的解释。

In this case, removing the reference to the tlb file, and then adding it again solved the problem

Unfortunately, I never did find a general solution, or an explanation for the behaviour.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文