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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:16:42+00:00 2026-05-29T10:16:42+00:00

I made the following method for creating interface instance. static IFBIndexItem* CreateFBIndexItemPtr() { IFBIndexItemPtr

  • 0

I made the following method for creating interface instance.

static IFBIndexItem* CreateFBIndexItemPtr()
{
    IFBIndexItemPtr pFBComWrapper;
    HRESULT hr = pFBComWrapper.CreateInstance(__uuidof(FBIndexItem));
    if (FAILED(hr)) {
        throw new _com_error(hr);
    }
    return pFBComWrapper;
}

It works fine, but since I have multiple interfaces, I want to create a template method. So here is the resulted method, but it throws “Class not registered” exception.

template<class T>
static T* CreateInterfacePtr()
{
    _com_ptr_t <_com_IIID<T, &__uuidof(T)>> pFBComWrapper;
    HRESULT hr = pFBComWrapper.CreateInstance(__uuidof(T));
    if (FAILED(hr)) {
        throw new _com_error(hr);
    }
    return pFBComWrapper;
}

I wonder why it doesn’t work correctly. Thanks.

  • 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-29T10:16:44+00:00Added an answer on May 29, 2026 at 10:16 am

    The problem is you pass the UUID of the interface in place of the class id into CreateIsntance().

    Of course CreateInstance() will fail when used like that – there’s (normally) no COM-exposed class with the same id as the interface. Also more than one class can implement the same interface, so naturally you will want to be able to pass different class ids for the same interface.

    Hence you need to have two parameters in your function – the interface and the class id (or the class itself from which you can get the class id using __uuidof).

    Also you have a serious ownership problem in your code. The function returns a raw pointer extracted from a smart pointer that is destroyed when function returns. This will likely lead to the object being released and the pointer becoming dangling.

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

Sidebar

Related Questions

I have made the following method which runs hard-coded xPath queries in a hard-coded
I have created a sitecollection and in AAM I have made following settings for
I made the following programs in Perl before: my $db = DBconnection with DB2
I made the following simulation: byte[] b = new byte[256]; for (int i =
In my Fortran code I made the following call to the dnrm2 routine: d
Very simple question, I made the following program : #include <stdlib.h> int main(int argc,
I am currently doing a code review and the following code made me jump.
I recently made my own Javascript library and I initially used the following pattern:
I have an application that is made up of the following: A central database
I am searching the following words in .todo files: ZshTabCompletionBackward MacTerminalIterm I made the

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.