Solved

C# Calling COM

Posted on 2003-12-04
2
343 Views
Last Modified: 2010-04-16
All,
i have an unmanaged C++ COM object, can i call it directly form C# ? if so, could you outline the steps please ?
thanks
0
Comment
Question by:Shay050799
2 Comments
 
LVL 6

Accepted Solution

by:
townsma earned 50 total points
ID: 9878631
Using an unmanaged C++ COM object is pretty straight forward.  Firstly, in the Solution Explorer locate you form, and the entry called References. Right click on References to Add Reference. On the selection form select the COM Tab.  Scroll down the list to locate the COM object you require.  If your COM Object isn't listed, you may not have registered you object. Finally use the Select button to add a reference to you COM Object.

Within you code you will need to make a variable of the type of your COM Object, this variable is then used to call the methods and properties of the COM Object.  See sample code below.

      COMSCORINGLib.PlayersClass oPlayers = new COMSCORINGLib.PlayersClass();
      oPlayers.GetRS();

COMSCORINGLib is the name of the COM Object.
PlayersClass is the name of a class within the COM Object.
oPlayers is a local variable to hold the instance of the COM Object.
GetRS() is a method within the class.

Hope this helps, good luck.
0
 
LVL 4

Expert Comment

by:bsmuehmer
ID: 9881660
for more information on this topic there is an excellent book:

.NET and COM: The Complete Interoperability Guide
by Adam Nathan

Paperback: 1608 pages
Publisher: SAMS; 1st edition (January 31, 2002)
ISBN: 067232170X
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question