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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:27:40+00:00 2026-05-11T09:27:40+00:00

After much help from all my StackOverFlow brethren, I managed to create a C++

  • 0

After much help from all my StackOverFlow brethren, I managed to create a C++ DLL that calls my C# classes via COM and passes data back and forth to an external application. There was much celebration in the kingdom after that code started working.

Now I have a new problem. I’m expanding the DLL so that it can call different classes (all implementing the same interface). I need to decide what class to call depending on a char array passed to the DLL when it is loaded. The methods I call are exactly the same regardless of which class I use. What is the best way to switch between classes when calling the DLL?

 // Initialize COM.   HRESULT hr = CoInitialize(NULL);    // I want to do something like this....but how?  if (strcmp(modelType, 'Model1') == 0) {          IUnitModelPtr pIUnit(__uuidof(ClassOne));     }         if (strcmp(modelType, 'Model2') == 0) {          IUnitModelPtr pIUnit(__uuidof(ClassTwo));     }   //call method 1  //call method 2  CoUninitialize();  //exit 

This is probably a fairly simple question, but I really do not know any C++. Just getting COM going was a major challenge for me.

edit: Im sure there are some super elegant ways to achieve this (reflection?) but please limit your suggestions to stuff that can be implemented easily….efficiency is not important here and maintainability is not really an issue.

  • 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. 2026-05-11T09:27:41+00:00Added an answer on May 11, 2026 at 9:27 am

    Do smth like this:

    GUID classId = GUID_NULL; if( strcmp( modelType, 'Model1' ) == 0 ) {     classId = __uuidof( class1 ); } else if( strcmp( modelType, 'Model2' ) == 0 ) {     classId = __uuidof( class2 ); } else if(... etc, continue for all possible model types } IUnitModelPtr unit; unit.CreateInstance( classId ); // interface methods can be called here 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 120k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Unfortunately I have a solution myself. All you have to… May 12, 2026 at 12:15 am
  • Editorial Team
    Editorial Team added an answer You can use the following simple expression. ^([0-9]-?){7,8}[0-9]$ The drawback… May 12, 2026 at 12:15 am
  • Editorial Team
    Editorial Team added an answer Put this in your ~/.inputrc: C-L: backward-kill-line (assuming by "clear"… May 12, 2026 at 12:15 am

Related Questions

I have the following output structure of executables in my solution: %ProgramFiles% | +-[MyAppName]
I come to you to see if someone has an idea on how to
I am attempting to extract all instances of a particular format from a string:
I have a stupid java logging problem: I'm loading the logging configuration from my

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.