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 296971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:35:50+00:00 2026-05-12T06:35:50+00:00

I am building an ATL type library with a type of class factory. Something

  • 0

I am building an ATL type library with a type of class factory. Something sorta like this:

[ object, uuid(...), ... ]
interface INumber : IDispatch {
    [propget, id(0)] HRESULT Value([out, retval] LONG* pVal);
}

[ object, uuid(...), ... ]
interface INumberFactory : IDispatch {
    [id(1)] HRESULT GetNumber([in] BSTR numberName, [out, retval] INumber* pVal);
}

[ uuid(...) ]
coclass NumberFactory {
    [default] interface INumberFactory;
}

The user can then get an instance of a class that implements the INumber interface through the NumberFactory.

This works well, but I cannot figure out how to define and instantiate the ATL objects that are returned through the NumberFactory.GetNumber() method. If I define the numbers in the IDL like this:

[ uuid(...) ]
coclass One {
    [default] interface INumber;
}

the One coclass can be instantiated by the user. But I would like to restrict it so the only way you can get an instance of the One coclass is by calling NumberFactory.GetNumber("One").

So my question is: How should the IDL be written so the user cannot instantiate One, but still be able to instantiate One from within then NumberFactory coclass and return the INumber interface of One to the user?

Additionally, is there anything special that must be done in the ATL side of things in order for this to work?

  • 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-12T06:35:50+00:00Added an answer on May 12, 2026 at 6:35 am
    1. Remove the CoClass from the IDL
    2. Remove the CoClass from the object table (remove its OBJECT_ENTRY_AUTO)
    3. Keep The CNumber class
    4. Your code for GetNumber(…) should look something like:
    *pVal = new CComObject<CNumber>();  
    (*pVal)->AddRef();
    

    This way there is no CoClass to create by the user and your factory is the only one who can produce them.

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

Sidebar

Related Questions

Building on from a previous query regarding Class::Struct vs Object::Accessor, I'd like to find
Building a website. When I order my tags like this, LightCycle works but Lightbox
building upon the $.fn.serializeObject() function from this question , i'd like to be able
Building a stand alone WPF application that uses a MSSQL backend. I would like
Building a simple app here; the methods in question: static coin class public static
Building our Android app from Ant fails with this error: [apply] [apply] UNEXPECTED TOP-LEVEL
Building on this question , is there a simple solution for having a multi-key
Building on this this post , I needed a clean way to extract nodes
Building off Does Perl have an enumeration type? , how can I perform dynamic
I think this is pretty basic. Today I was building a dynamic link project

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.