简体   繁体   中英

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

I got the following COM object

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

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.

You can use SysInternals' Process Monitor to observe the way the registry is used. Both by Regasm.exe and the VBS scripting engine (usually 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. Unless you explicitly run c:\\windows\\syswow64\\cscript.exe so you get the 32-bit version.

64-bit programs look in HKLM\\Software\\Classes\\CLSID, 32-bit programs look in HKLM\\Software\\Wow6432Node\\Classes\\CLSID. Note the added Wow6432Node. An appcompat feature that ensures that programs don't crash when they accidentally load an executable file with the wrong bitness.

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. A fairly inevitable side-effect of VS being a 32-bit process. If you register it yourself with Regasm.exe then be sure the pick the correct one. The 64-bit version that will write the 64-bit keys lives inside C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319, note "Framework64".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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