简体   繁体   English

Vista中的VB6 .NET互操作问题

[英]VB6 .NET interop issue in Vista

I wrote an assembly in C# and I needed to invoke a method on the DLL from a VB6.0 application. 我用C#编写了程序集,并且需要从VB6.0应用程序调用DLL上的方法。 I made the DLL COM compliant and registered the DLL accordingly. 我使DLL COM兼容并相应地注册了DLL。 From my VB application I would then instantiate the class in the .NET assembly using the VB6.0 CreateObject method. 然后,从VB应用程序中,我将使用VB6.0 CreateObject方法在.NET程序集中实例化该类。

Set dotNetObj = CreateObject("Namespace.ClassName")

I would then be able to invoke any method on that class. 然后,我将能够在该类上调用任何方法。

The Problem: 问题:

All worked fine, until I tried executing the code on a Vista machine. 一切正常,直到我尝试在Vista机器上执行代码。 Whenever I execute the exe it works fine, but whenever the exe is executed using the 'run as administrator' option the following error appears: 每当我执行exe时,它都可以正常工作,但是只要使用“以管理员身份运行”选项执行exe,就会出现以下错误:

"ActiveX component can`t create object." “ ActiveX组件无法创建对象。”

I need this EXE to run in admin mode, else certain areas of the legacy system won't work. 我需要此EXE在管理模式下运行,否则旧版系统的某些区域将无法工作。

Any ideas on why the CreateObject would not work in admin mode? 关于为何CreateObject无法在管理模式下工作的任何想法?

It sounds like maybe the COM component is only registered for the user - so when the admin tries it, the clsid is unknown. 听起来好像COM组件只是为用户注册的-因此,当管理员尝试使用该组件时,clsid是未知的。 Try running your isntallation/registration process for the admin. 尝试为管理员运行您的注册/注册过程。

(does vista put clsids in HKCU? or just HKLM?) (vista是在HKCU或在HKLM上放了吗?)

A quick search seems to indicate that it relates to whether UAC is enabled or disabled... with it enabled it looks in HKCU... disabled and it looks in HKLM. 快速搜索似乎表明它与是否启用或禁用UAC有关...启用它后,它会在HKCU中显示...已禁用并在HKLM中显示。 So if you are installing into HKCU, it won't be there for an admin with UAC disabled. 因此,如果您要安装到HKCU中,则禁用UAC的管理员将无法使用它。

Because it is only registered in the user space? 因为它仅在用户空间中注册?

Try to register your dll in an admin shell 尝试在管理外壳中注册您的dll

regasm mycomponent.dll /register /codebase /tlb

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

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