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

  • SEARCH
  • Home
  • 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 8053329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:48:34+00:00 2026-06-05T07:48:34+00:00

I write a C# class library and want to use it in vbscript. Here

  • 0

I write a C# class library and want to use it in vbscript.
Here is my code:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.PointOfService;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Reflection;
using System.ComponentModel;

namespace IndigoDynamic
{
    #region class implements IAsyncResult
    [ProgId("IndigoDynamic.VirtualManager")]
    [ClassInterface(ClassInterfaceType.AutoDispatch)]
    [ComVisible(true)]
    public class AsyncResult : IAsyncResult
    {
        object _state;
        private bool m_completed;
        private System.Threading.ManualResetEvent m_handle;
        private Exception m_exception;

        public bool IsCompleted
        {
            get { return m_completed; }
            set { m_completed = value; }
        }

        public System.Threading.WaitHandle AsyncWaitHandle
        {
            get { return m_handle; }
            set { m_handle = (System.Threading.ManualResetEvent)value; }
        }

        public object AsyncState
        {
            get
            {
                if (Exception != null)
                {
                    throw Exception;
                }
                return _state;
            }
            internal set
            {
                _state = value;
            }
        }

        public bool CompletedSynchronously { get { return IsCompleted; } }

        internal Exception Exception
        {
            get { return m_exception; }
            set { m_exception = value; }
        }
    }
    #endregion

    #region extends CashDrawer
    [ProgId("IndigoDynamic.VirtualManager")]
    [ClassInterface(ClassInterfaceType.AutoDispatch)]
    [ComVisible(true)]
    public class MyCashDrawer
    {
        private CashDrawer me;
        public delegate void status_callback(int newstatus);

        private status_callback myF;

        public MyCashDrawer(CashDrawer param)
        {
            me = param;
            me.StatusUpdateEvent += new StatusUpdateEventHandler(this.StatusUpdate);
        }

        [ComVisible(true)]
        public void Claim(int timeout) { me.Claim(timeout); }

        [ComVisible(true)]
        public void Close() { me.Close(); }

        [ComVisible(true)]
        public void Open() { me.Open(); }

        [ComVisible(true)]
        public void OpenDrawer() { me.OpenDrawer(); }

        [ComVisible(true)]
        public void Release() { me.Release(); }

        [ComVisible(true)]
        public void Release(int timeout, int freq, int duration, int delay)
        {
            me.WaitForDrawerClose(timeout, freq, duration, delay);
        }

        [ComVisible(true)]
        public int StatusClosed() { return CashDrawer.StatusClosed; }

        [ComVisible(true)]
        public int StatusOpen() { return CashDrawer.StatusOpen; }

        [ComVisible(true)]
        public bool Claimed() { return me.Claimed; }

        [ComVisible(true)]
        public bool DeviceEnabled() { return me.DeviceEnabled; }

        [ComVisible(true)]
        public bool DrawerOpened() { return me.DrawerOpened; }

        [ComVisible(true)]
        public ControlState State() { return me.State; }

        [ComVisible(true)]
        public void addStatusCallback(status_callback f)
        {
            myF = f;
        }

        [ComVisible(true)]
        public void removeStatusCallback(status_callback f)
        {
            if (myF == f)
                myF = null;
        }

        [ComVisible(true)]
        private void StatusUpdate(object sender, StatusUpdateEventArgs arg)
        {
            if (myF != null)
                myF(arg.Status);
        }
    }
    #endregion

    [ProgId("IndigoDynamic.VirtualManager")]
    [ClassInterface(ClassInterfaceType.AutoDispatch)]
    [ComVisible(true)]
    class VirtualManager : ISynchronizeInvoke
    {
        private readonly object _sync;

        // Constructor
        public VirtualManager()
        {
            _sync = new object();
        }

        #region implements methods of ISynchronizeInvoke
        public IAsyncResult BeginInvoke(Delegate method, object[] args) {
            AsyncResult result = new AsyncResult();

            System.Threading.ThreadPool.QueueUserWorkItem(delegate {
                result.AsyncWaitHandle = new System.Threading.ManualResetEvent(false);
                try {
                    result.AsyncState = Invoke(method, args);
                } catch (Exception exception) {
                    result.Exception = exception;
                }
                result.IsCompleted = true;
            });

            return result;
        }

        public object EndInvoke(IAsyncResult result) {
            if (!result.IsCompleted) {
                result.AsyncWaitHandle.WaitOne();
            }

            return result.AsyncState;
        }


        public object Invoke(Delegate method, object[] args) {
            lock (_sync) {
                return method.DynamicInvoke(args);
            }
        }

        public bool InvokeRequired {
            get { return true; }
        }
        #endregion

        [ComVisible(true)] 
        public MyCashDrawer getCashDrawer()
        {
            PosExplorer posExplorer = new PosExplorer(this);
            DeviceInfo deviceInfo = posExplorer.GetDevice(DeviceType.CashDrawer);
            if (deviceInfo == null)
            {
                //<report failure >
                return null;
            }
            else
            {
                CashDrawer cd = posExplorer.CreateInstance(deviceInfo) as CashDrawer;

                return new MyCashDrawer(cd);
            }
        }

        [ComVisible(true)]
        public MyCashDrawer getCashDrawer(String name)
        {
            PosExplorer posExplorer = new PosExplorer(this);
            DeviceInfo deviceInfo = posExplorer.GetDevice(DeviceType.CashDrawer, name);
            if (deviceInfo == null)
            {
                //<report failure >
                return null;
            }
            else
            {
                CashDrawer cd = posExplorer.CreateInstance(deviceInfo) as CashDrawer;
                return new MyCashDrawer(cd);
            }
        }

        [ComRegisterFunction()]
        public static void RegisterClass(string key)
        {
            StringBuilder sb = new StringBuilder(key);
            sb.Replace(@"HKEY_CLASSES_ROOT\", "");

            RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

            RegistryKey ctrl = k.CreateSubKey("Control");
            ctrl.Close();

            RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
            inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
            inprocServer32.Close();

            k.Close();
        }

        [ComUnregisterFunction()]
        public static void UnregisterClass(string key)
        {
            StringBuilder sb = new StringBuilder(key);
            sb.Replace(@"HKEY_CLASSES_ROOT\", "");

            RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

            if (k == null)
            {
                return;
            }
            k.DeleteSubKey("Control", false);

            RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
            inprocServer32.DeleteSubKey("CodeBase", false);
            inprocServer32.Close();
            k.Close(); 
        }
    }
}

After building, I use RegAsm but it threw Warning No types are registered.
Then I write a sample code in vbs but it says ActiveX can not create Object.

Sub main
    set objTest = CreateObject("IndigoDynamic.VirtualManager")
end sub

call main

Somebody said that I have to check AssemblyInfo.cs and make sure I have

[assembly: ComVisible(true)]

Of course I have, but problem is still not solved.
Can anybody tell me a solution?


I change my code like that. More simple, no threading, no interface, all is public.
But it still doesn’t work.
Please, I really need help.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.PointOfService;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Reflection;
using System.ComponentModel;

namespace IndigoDynamic
{            
    [ProgId("IndigoDynamic.VirtualManager")]
    [ClassInterface(ClassInterfaceType.AutoDispatch)]
    [ComVisible(true)]
    public class VirtualManager
    {   
        public VirtualManager()
        {
        }

        [ComVisible(true)] 
        public CashDrawer getCashDrawer()
        {
            PosExplorer posExplorer = new PosExplorer();
            DeviceInfo deviceInfo = posExplorer.GetDevice(DeviceType.CashDrawer);
            if (deviceInfo == null)
            {
                //<report failure >
                return null;
            }
            else
            {
                CashDrawer cd = posExplorer.CreateInstance(deviceInfo) as CashDrawer;
                return cd;
            }
        }

        [ComVisible(true)]
        public CashDrawer getCashDrawer(String name)
        {
            PosExplorer posExplorer = new PosExplorer();
            DeviceInfo deviceInfo = posExplorer.GetDevice(DeviceType.CashDrawer, name);
            if (deviceInfo == null)
            {
                //<report failure >
                return null;
            }
            else
            {
                CashDrawer cd = posExplorer.CreateInstance(deviceInfo) as CashDrawer;
                return cd;
            }
        }

        [ComRegisterFunction()]
        public static void RegisterClass(string key)
        {
            StringBuilder sb = new StringBuilder(key);
            sb.Replace(@"HKEY_CLASSES_ROOT\", "");

            RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

            RegistryKey ctrl = k.CreateSubKey("Control");
            ctrl.Close();

            RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
            inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
            inprocServer32.Close();

            k.Close();
        }

        [ComUnregisterFunction()]
        public static void UnregisterClass(string key)
        {
            StringBuilder sb = new StringBuilder(key);
            sb.Replace(@"HKEY_CLASSES_ROOT\", "");

            RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

            if (k == null)
            {
                return;
            }
            k.DeleteSubKey("Control", false);

            RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
            inprocServer32.DeleteSubKey("CodeBase", false);
            inprocServer32.Close();
            k.Close(); 
        }
    }
}
  • 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-06-05T07:48:35+00:00Added an answer on June 5, 2026 at 7:48 am

    You are unfortunately very far removed from a workable solution. The warning is accurate, none of the classes you made [ComVisible] at creatable by a COM client. MyCashDrawer is missing the required default constructor, a COM client app cannot pass arguments to a constructor. VirtualManager isn’t public and derives from an interface that’s not [ComVisible]

    The code is also missing the required implementations for interfaces that makes an ActiveX component work on a ActiveX host window, like IOleObject, IOleInPlaceObject, IOleInplaceActiveObject, IOleWindow, IViewObject, etcetera. Furthermore, you are exposing implementation details that an ActiveX object can’t take care of, the threading model in COM is very different from the one in .NET.

    You are going to need a seriously different approach. Consider deriving the visible object from System.Windows.Forms.Control, it takes care of the minimum ActiveX interface implementation requirements. And make threading your problem, don’t leave it up to the client to sort it out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My main solution is using code from a utility class library, that I wrote
I want to write a class library that works in ASP.NET and standalone applications.
I want to write a library for my Arduino(header and class files), but I
Suppose I write a library with the following: public class Bar { /* ...
Assume a .NET class library code that, for example, writes to the Windows registry
I want to write class whose constructor takes two parameters, but the arguments are
Possible Duplicate: When to Use Static Classes in C# I will write code in
I need to write an assembly (C#.net 2.0 class library) to monitor all applications
In Eclipse once I put a library on the class path, I can use
As stated, I'm trying to use the class library in the application. Specifically, I've

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.