Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7610879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:31:33+00:00 2026-05-31T01:31:33+00:00

I have a C# class library project (dll) with a single class, COMTest: using

  • 0

I have a C# class library project (dll) with a single class, COMTest:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace COMTest
{
    [Guid("45D639E4-FDDE-4b7b-A35F-FC19856DFF24")]
    [ComVisible(true)]
    public class Foo
    {
        public Foo()
        {
            Console.WriteLine("Constructing Foo");
        }

        private string mName = "FOO";
        public string Name
        {
            get { return mName; }
            set { mName = value; }
        }
    }
}

The project is registered for COM interop, and the assembly is COM-visible. The target framework is .Net 3.5, and the platform target is x86. The .dll is registered using the 32-bit C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe /codebase COMTest.dll

I am attempting to access this class from VBScript (again, 32-bit, using C:\Windows\SysWOW64\cscript.exe test.vbs), but I appear to be having problems acquiring an instance of Foo within the script. I can use the class; I just can’t keep any reference to it.

Here is my script:

Wscript.Echo "CreateObject(""ComTest.Foo"").Name Results: " + CreateObject("COMTest.Foo").Name
IF IsEmpty(CreateObject("COMTest.Foo")) THEN Wscript.Echo "CreateObject() is empty" ELSE Wscript.Echo "CreateObject() is NOT empty"

DIM foo : CreateObject("COMTest.Foo")
IF IsEmpty(foo) THEN Wscript.Echo "foo is empty" ELSE Wscript.Echo "foo is NOT empty"

And here is the output:

Constructing Foo
CreateObject("ComTest.Foo").Name Results: FOO
Constructing Foo
CreateObject() is NOT empty
Constructing Foo
foo is empty

As you can see, the CreateObject() call succeeds–I’m just unable to keep a reference to the object returned (in foo).

I feel like I’m missing something simple. How do I retain the object returned from CreateObject()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:31:34+00:00Added an answer on May 31, 2026 at 1:31 am

    The colon you use in line three doesn’t actually do anything, it just separates two different statements. Your Dim foo : CreateObject("COMTest.Foo") is equivalent to:

    Dim foo
    CreateObject("COMTest.Foo")
    

    Which creates the object but doesn’t actually set its reference to any variable. I would write it like this:

    Dim foo
    Set foo = CreateObject("COMTest.Foo")
    WScript.Echo foo.Name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a dll in C++ using a Class Library project in Visual
I have a class library project that references the version 4.1 Microsoft.Practices.Common dll. I
I have a Class library project. I am installing this dll produced by the
I have a c# class library project that uses a COM dll registered on
Using Delphi XE on Win7 x64, have Jedi Class Library ver. 3.45, and 7z.dll
Assume I have a class library project name Utilities.dll as follows: public static class
I have a Class Library project and MVC project in the one solution. My
I have a class library project which contains some content files configured with the
I am trying to access database from a Class Library Project. I have connection
I have a class, which is part of a code library project that was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.