开发者

VB6 COM Object - only works when IDE is running?

开发者 https://www.devze.com 2023-02-06 00:53 出处:网络
I have an ancient COM object in VB6 that has been working fine until recently. (Don\'t they all). The only code 开发者_Go百科change that has been made (as verified by svn) is the inclusion of a new st

I have an ancient COM object in VB6 that has been working fine until recently. (Don't they all). The only code 开发者_Go百科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:

VB6 COM Object - only works when IDE is running?

(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.


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.


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..


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号