VB6 COM 对象 - 仅在 IDE 运行时有效?

发布于 2024-10-12 22:23:21 字数 880 浏览 2 评论 0原文

我在 VB6 中有一个古老的 COM 对象,直到最近它一直工作正常。 (不是全部)。唯一的代码更改(经 svn 验证)是在数组中包含新的字符串文字。

VB6 IDE 可以很好地编译该对象。当我点击“运行|开始...”并从命令提示符执行以下测试 vb 脚本时,该对象工作正常,并且我看到了预期的对话框:

dim o

set o = CreateObject("MyDll.MyClassName")

wscript.Echo "Testing object" 
wscript.Echo o.HelloWorld     ' runs a test method that returns "Hello World"
wscript.Echo "Done"

但是,当我在 IDE 中停止调试并尝试运行相同的 vb 脚本时从同一命令提示符处,我收到错误:

alt text

(出于安全原因删除了 ProgID,但它与

我尝试过的事情:

  1. 我怀疑当我启动和停止调试器时,VB 可能已注册和取消注册 DLL,因此我还尝试使用 regsvr32 在运行测试脚本之前。这没有效果。

  2. 我还从注册表中删除了对该 DLL 的所有引用,并重新注册了该对象。同样的错误。

  3. 我删除了 DLL,然后从 VB 中重新构建它(File|Make...)并重新注册了 DLL。同样的错误。

机器是Win7 Ultimate x64,用VB6构建的对象。

有什么建议吗?

而且,不幸的是,用 C# 重写对象不是一个选项。

I have an ancient COM object in VB6 that has been working fine until recently. (Don't they all). The only code change that has been made (as verified by svn) is the inclusion of a new string literal in an array.

The VB6 IDE compiles the object fine. When I hit Run|Start... and execute the following test vb script from the command prompt, the object works fine and I see the dialog boxes I expect:

dim o

set o = CreateObject("MyDll.MyClassName")

wscript.Echo "Testing object" 
wscript.Echo o.HelloWorld     ' runs a test method that returns "Hello World"
wscript.Echo "Done"

However, when I stop debugging in the IDE and attempt to run the same vbscript from the same command prompt, I get the error:

alt text

(ProgID removed for security reasons, but it is the same as in the script.)

Things I've tried:

  1. I suspected that the DLL may have been registered and unregistered by VB when I start and stop the debugger, so I also tried registering the object with regsvr32 before running the test script. This has had no effect.

  2. I also removed all references to the DLL from the registry, and re-registered the object. Same error.

  3. I deleted the DLL and re-built it from VB (File|Make...) and re-registered the DLL. Same error.

Machine is Win7 Ultimate x64, object built with VB6.

Any suggestions?

And, no, unfortunately, rewriting the object in C# isn't an option.

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

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

发布评论

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

评论(3

蝶舞 2024-10-19 22:23:21

微软表示这是某种依赖性问题:http://support.microsoft.com/kb/194801

因为当您在 IDE 中运行该对象时它正在工作,所以这给您留下了四种可能性:

  1. ActiveX dll 本身不在系统路径上。
  2. ActiveX dll 依赖于不在系统路径上的其他内容。
  3. 注册 dll 后,它会以某种方式标记为需要提高安全性才能运行
  4. 注册 dll 后,它所依赖的某些东西需要提高安全性才能运行。

我会尝试以管理员身份打开命令提示符,然后运行启动该对象的 vbscript 文件。如果有效,则意味着问题是#3 或#4。如果没有,则表示#1 或#2。

如果 ActiveX dll 没有外部依赖项,则可以消除 #2 和 #4。

接下来,我将查看事件日志,看看 Windows 是否记录了与此相关的任何其他错误。

更新

刚刚发现了另一个可能的原因。如果ActiveX dll是32位的,那么脚本必须使用32位版本的脚本引擎才能运行;否则它将给出此错误,因为默认脚本引擎(该机器上的 x64)实际上无法找到该 dll。

我相信如果你使用 \windows\system32\cscript.exe 来运行你的 vbscript 那么你会很好。

Microsoft says it's some sort of dependency issue: http://support.microsoft.com/kb/194801

Because it's working when you run the object in the IDE this leaves you with four possibilities:

  1. The ActiveX dll itself is not on the system path.
  2. The ActiveX dll depends on something else which is not on the system path.
  3. After registering the dll, it is somehow marked as requiring elevated security to run
  4. After registering the dll, something it depends on requires elevated security to run.

I would try opening a command prompt as administrator then run your vbscript file that starts the object. If that works then it means the problem is either #3 or #4. If it doesn't, then it means #1 or #2.

You can eliminate #2 and #4 if the ActiveX dll has no external dependencies.

Next, I'd look in my event log to see if any other errors were logged by windows about this.

UPDATE

Just found another possible cause. If the ActiveX dll is 32-bit, then the script has to use the 32-bit version of the script engine to run; otherwise it will give this error because the default script engine (x64 on that machine) literally can't find the dll.

I believe if you use \windows\system32\cscript.exe to run your vbscript then you'll be good.

七堇年 2024-10-19 22:23:21

好吧,这听起来肯定是因为 32 位 dll 导致的问题。上面提到的建议是正确的,但路径是错误的。尝试使用 C:\Windows\SysWOW64 中的 CSCRIPT ..

Well it definitely sounds like the issue because of 32bit dll.. The suggestion mentioned above is correct but the path is wrong.. try using the CSCRIPT from C:\Windows\SysWOW64..

失去的东西太少 2024-10-19 22:23:21

尝试使用 %Windows%\SysWOW64 中的 regsvr32.exe 注册 DLL。它与 %Windows%\System32(在 64 位操作系统上)中的 regsvr32.exe 不同。

请参阅此SO 帖子

Try registering the DLL with regsvr32.exe from %Windows%\SysWOW64. It is different than the regsvr32.exe in %Windows%\System32 (on a 64-bit OS).

See this SO posting.

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