How can I build a COM from C++, which can be fed into C Sharp code?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How can I build a COM from C++, which can be fed into C Sharp code?

  1. #1
    Join Date
    Aug 2005
    Location
    Richmond, Canada
    Posts
    2

    How can I build a COM from C++, which can be fed into C Sharp code?

    Hi, all:

    Sorry for my entry-level question. Just as in the title:

    "How can I build a COM from C++, which can be fed into C Sharp code?"
    Welcome to Vision Open
    http://www.visionopen.com

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: How can I build a COM from C++, which can be fed into C Sharp code?

    Building COM components in C++ is non-trivial - you need a lot of knowledge of C++ as a language as well as a good understanding of what COM is.

    There are wizards in Visual Studio to create COM objects in C++ but personally I'd not attempt this until you've learned how to use C++.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    May 2011
    Posts
    18

    Re: How can I build a COM from C++, which can be fed into C Sharp code?

    First, you should get a handle on making Windows API calls from C#.

    http://www.c-sharpcorner.com/UploadF.../win32api.aspx

    Second, Once you have an understanding on how that works, your next step, is to build a small DLL in C++ that while expose the symbols (methods and properties) you want to be able to call from C#. I would just start with a single method that you feed in a param and return a result. You will want to try a couple methods that accepts different param type.. (i.e. string, int/long, arrays).

    Third, Now it is time to actually make the call from C# to the C++ DLL. It will me similar to Step 1 where you made calls to the Windows API dll's.

    Fourth, Once you get that working, it would probably be best to create a "Wrapper Class" in C#. Its purpose will be to make the calls to C++ and have all the code of parsing out the results and placing them in nice and clean C# variables. It takes a little bit of work to make calls and receive results from C++. So basically for every C++ method you have, you should have a C# wrapper method. Then your form or whatever will just call the C# wrapper method and you won't have to worry about all the conversion code each and every time you want to make a call to C++.

    Like darwen said, it is not trivial, as you can see even by my very simplistic explanation. there is a learning curve as not only do you need to know C# and C++, the data types between the two languages isn't always apples to apples.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a Codeguru.com survey!


HTML5 Development Center