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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:58:05+00:00 2026-06-06T15:58:05+00:00

I have a c++ class which needs to interact with a .NET dll using

  • 0

I have a c++ class which needs to interact with a .NET dll using COM interop.

I have:

1.
A method called from the C++ which operating object is the .net instance:

   m_pCommManager.CreateInstance(__uuidof(CHmHTTPManager));
    m_pCommManager->Communicate(/*string parameter*/);

2.
A .net interface with the following method, which the C++ class should comply to:

 void ResponseRecieved(/*string parameter*/)

My question is: What is the parameter type I should select that is:

A.
Easy for manipulation as a string on both sides (even through casting).

B.
Acceptable by both environments (I cannot use “string” for C++ and .net as it’s not the same)

Concrete usage examples are more than welcome.

  • 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-06T15:58:07+00:00Added an answer on June 6, 2026 at 3:58 pm

    You should use a BSTR string in C++.

    From MSDN:

    A BSTR is a composite data type that consists of a length prefix, a
    data string, and a terminator. The following table describes these
    components.

    BSTRs are allocated using COM memory allocation functions, so they can
    be returned from methods without concern for memory allocation.

    In the IDL file for your COM object it would be:

    HRESULT mySampleMethod([in] BSTR mySampleParam);
    

    How the actual code in C++ will look like will depend on the type of COM object/Type Library you are developing (I mean whether you are using an MFC-based COM object or an ATL-based one). On any case I recommend you to use the wizard from Visual Studio to create/modify your type library.

    In the .Net side, you just use the normal string type, and it will be marshaled automatically if the parameter is defined as BSTR in the type library of your COM object.

    You may also find this question useful:

    Convention for passing BSTRs into COM functions from C# (COM interop)

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

Sidebar

Related Questions

I have a class A which has a private method called a(). I have
i have a validation class which needs improving. If I require some custom validation
You have a Python class which needs an equals test. Python should use duck-typing
I have a initApp.as which instantiates a class which needs to access the currentState
I have a form builder class which inherits from AbstractType and I need to
I have a program in which I need to store a Class object into
I need clarification in calling methodologies, i have a base class and from which
I have a .NET 2.0 class the properties of which are marked virtual.I need
I am working on a .NET project, which needs to interact with some user
Imagine you have class A which has code which runs as method M. And

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.