Solved

C# Calling COM

Posted on 2003-12-04
2
341 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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