简体   繁体   English

无法创建名称为“”的对象COM

[英]The object with the name “” could not be created COM

I got the following COM object 我得到以下COM对象

namespace PCKTicketCOM
{
   [Guid("0057ddf4-7125-485b-b963-5d2b338040bc"),
   InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
   public interface IPCKTicketCOM
   {
       [DispId(1)]
       int AddTheseUp(int adder1, int adder2);
   }

   [Guid("3c63584c-f51a-4ce8-8f24-734686895cba"),
   ClassInterface(ClassInterfaceType.None)]
   public class PCKTicketCOM : IPCKTicketCOM
   {
        // a method that returns an int
        public int AddTheseUp(int adder1, int adder2)
        {
            return adder1 + adder2;
        }
   }
}

And trying to call it via VBS and i always get the error 并试图通过VBS调用它,我总是得到错误

The object with the name "PCKTicketCom.PCKTicketCOM" could not be created

and I'm rather clueless on how to solve this. 我对如何解决这个问题一无所知。

dim objTest, intResult
Set objTest = WScript.CreateObject("PCKTicketCOM.PCKTicketCOM")

intResult =  objTest.AddTheseUp(100,200)
WScript.echo "Result = " & intResult

I also can't seem to find anything regarding this problem using google, any help would be appreciated. 我也似乎无法使用Google找到有关此问题的任何信息,我们将不胜感激。

You can use SysInternals' Process Monitor to observe the way the registry is used. 您可以使用SysInternals的Process Monitor观察注册表的使用方式。 Both by Regasm.exe and the VBS scripting engine (usually cscript.exe). Regasm.exe和VBS脚本引擎(通常是cscript.exe)都可以。 You'll easily see a mismatch that way. 这样您将很容易发现不匹配。

With the very common reason these days that you don't realize that the VBS scripting engine runs in 64-bit mode on a 64-bit operating system. 如今,由于非常普遍的原因,您没有意识到VBS脚本引擎在64位操作系统上以64位模式运行。 Unless you explicitly run c:\\windows\\syswow64\\cscript.exe so you get the 32-bit version. 除非您明确运行c:\\ windows \\ syswow64 \\ cscript.exe,否则您将获得32位版本。

64-bit programs look in HKLM\\Software\\Classes\\CLSID, 32-bit programs look in HKLM\\Software\\Wow6432Node\\Classes\\CLSID. 64位程序在HKLM \\ Software \\ Classes \\ CLSID中查找,而32位程序在HKLM \\ Software \\ Wow6432Node \\ Classes \\ CLSID中查找。 Note the added Wow6432Node. 请注意添加的Wow6432Node。 An appcompat feature that ensures that programs don't crash when they accidentally load an executable file with the wrong bitness. 一个appcompat功能,可确保程序在意外加载位错误的可执行文件时不会崩溃。

If you let Visual Studio register the server with the "Register for COM interop" option in the project's Build tab then only the 32-bit Wow6432Node registry keys will be written. 如果使用项目的“生成”选项卡中的“注册COM互操作”选项使Visual Studio注册服务器,则将仅写入32位Wow6432Node注册表项。 A fairly inevitable side-effect of VS being a 32-bit process. VS的不可避免的副作用是32位进程。 If you register it yourself with Regasm.exe then be sure the pick the correct one. 如果您用Regasm.exe自己注册,请确保选择正确的。 The 64-bit version that will write the 64-bit keys lives inside C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319, note "Framework64". 将写入64位密钥的64位版本位于C:\\ Windows \\ Microsoft.NET \\ Framework64 \\ v4.0.30319中,请注意“ Framework64”。

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

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