-
May 4th, 2011, 08:45 PM
#1
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?"
-
May 5th, 2011, 07:19 AM
#2
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.
-
May 5th, 2011, 08:46 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|