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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:10:53+00:00 2026-05-30T06:10:53+00:00

I have a header-file, the COM interface. I have created a small win32 program

  • 0

I have a header-file, the COM interface. I have created a small win32 program which works, but my main program is written in C#.

So I would like to import this COM object in my main program, but how do I do this, when the only thing I got is the header-file?

All places I’ve looked I need a tlb-file..?

I’m new to COM objects so just ask if you need some extra info, or have another workaround 🙂

[UPDATE]
First thanks for all the responses!
I’ve tried some different things, but haven’t solved my issue yet. In my research, I’ve found an article describing COM Interop http://msdn.microsoft.com/en-us/library/aa645736(v=vs.71).aspx#vcwlkcominteroppart1cclienttutorialanchor2

This haven’t helped me out. But I’ve found that I should be able to get moving if I can complete the following:

  1. Declaring a COM coclass:

    [ComImport, Guid("7C075F7F-FD71-40a2-AC63-0D0C4DB39ECA")]
    class CCamera
    {
        // Cannot have any members here 
        // NOTE that the C# compiler will add a default constructor
        // for you (no parameters).
    }
    
  2. Creating a COM class wrapper:

    [Guid("AD87369B-3BBA-4f1c-81C5-B92FCEA9A1F4"),
    InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 
    interface ICamera
    {
        //static HRESULT GetCameraInterface();
        bool StartPreview();
        bool StopPreview();
    }
    
    1. Using Casts Instead of QueryInterface:

    try
    {
    CCamera cam = new CCamera();
    ICamera test = (ICamera)cam;
    //test.StartPreview();
    }
    catch (Exception e)
    {
    Console.WriteLine(e.StackTrace);
    }

I get an invalid cast exception, so is this because I miss implementing some methods in the interface?
And how do I implement the following method from the c++ interface:

static  HRESULT GetCameraInterface(void __RPC_FAR *__RPC_FAR *ppvObject);

[SOLUTION]
OK I got a solution, but I never solved to wrap the interface.
Instead I created a C++ dll project and exposed the methods I needed. Then in my C# project, could I use these methods with DllImport. If anybody need more explanation on how I archived this, send me a message.

  • 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-30T06:10:55+00:00Added an answer on May 30, 2026 at 6:10 am

    If it is registered as a COM-Object, then you can import it via the Add Reference Dialog. Right click on the project –> Add Reference. Then select the Tab “COM” and you can select your COM Interface. Required Interop classes for .NET will be generated automatically.

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

Sidebar

Related Questions

I have C++ project (VS2005) which includes header file with version number in #define
Please see the class I have created at http://textsnip.com/see/WAVinAS3 for parsing a WAVE file
I have a header file like this: #ifndef __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #define __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #ifdef _DEBUG //
I have a header file, lets say Common.h, that is included in all of
I have a header file variable.h where i declare all my global variable.Then i
I have C header file containing the following type definition: // example.h typedef struct
I have a header file with all the enums listed (#ifndef #define #endif construct
I have this header file, zeeheader.h, and I wrote some classes in it, I'm
I have a c++ header file containing a class. I want to use this
I have some useful typedefs on a header file called utypes.h. I have decided

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.