tags:

views:

722

answers:

5

Instruction on accessing a interface to an application, in plain C/C++ without:

  • MFC
  • ATL
  • WTL

Basically, I would like to make use of a COM object.

Working sample source code or guidance - to using (functionality) a COM object, not creating a COM server.

Regards

+1  A: 

Well, assuming you have the interface declaration, all you need is a call to CoInitialize in order to initialize COM, then CoCreateInstance to get your instance (and use it), and then optionally, CoUnInitialize to uninitialize COM.

casperOne
CasperOne, do you have a small example? I'm not familiar to Windows programming - I'm from Linux world...
Aaron
+3  A: 

Here is a simple example in plain C++:

CoInitialize(NULL); // absolutely essential: initialize the COM subsystem
IMyInterface* pIFace;
// create the object and obtain a pointer to the sought interface
CoCreateInstance(CLSID_MyObject, NULL, CLSCTX_ALL, IID_IMyInterface, &pIFace);
pIFace->MethodIReallyNeed(); // use the object
pIFace->Release(); // free the object
CoUninitialize(); // cleanup COM after you're done using its services

Copied from here: COM Basics

1800 INFORMATION
1800 Information - thanks :)
Aaron
+1  A: 

There's an article on CodeProject, Introduction to COM - What It Is and How to Use It that you may find useful. It gives a pretty good introduction and a worked example.

ChrisN
A: 

Avoid codeproject (newbie), and see all MSDN chapters about COM.

Everything is there, with tons of C and C++ sample codes

A: 

Just refer a good book on COM (Don Box or Dale Rougerson). Those are the good starting points to COM World.

Vinay