OLE/COM Programming

Started by
7 comments, last by LordShade 18 years, 4 months ago
Hi guys, I am new to OLE/COM programming,I am learning how to build COM wrapper(ie. wordpad) to actually put into C++ application. I have been searching and searching but with no luck with any tutorials online that teaches good OLE/COM programming. I hope someone could give me some recommendation/advice on this topic. Thank you in advance. Hope to hear from you guys soon.:) TIA, Commy
Advertisement
MSDN is a good source. Also you can try a search on Google to see what you can come up with. There are a few sites that I use for reference with such things - Code Project.

Basically, with come you need to create a DLL for you class to reside in. Next, you will need to implement each function for any interface you derive from and also, the ones you create. All COM objects derive from IUnknown, so that’s three functions or methods as they are called that you will have to implement.

Next, you will not only need to write the implementations for you COM object(s), but also you will need to create an implementation for a class factory. The purpose of the class factory is to attach (or reference) an object to an interface.

You will also need to generate GUIDs for you interfaces and implementations (aka IID or CLSID). Or if you really want them in full, Interface Identifier and Class Identifier. Those IDs are passed to you class factory were YOU check to see if the one passed matches any of the ones YOUR COM objects implement. My explanations are less the adequate, so you should look up additional information on the topic.
Take back the internet with the most awsome browser around, FireFox
Hi Sakky,

Thanx for the quick reply. I really appreciate you reply. I did researched on Codeproject too,but came out lost and even confused in them.The basic understanding of the theory is there like what you mentioned. I will do more research again due to the problems.

1)Hooking up with those interfaces that I viewed in the ole/com viewer will help basically. But I created those interfaces. I was thinking could I actually just call CoCreateInstance() to get the interface?Then later found out could use ProgID to convert the name to get the interface. Then ....LOST! :(

2)Maybe someone could could give another piece of advice again.:(

Thank you and maybe a book to recommend will help too.:)

in despair,
Commy
This tutorial might help: OLE Drag and Drop from Scratch.

See also: The COM Programmer's Cookbook
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Thanx LessBread,

I will look into them and then post again. Thank you to anyone who help me in the way too.

in despair,
Commy
Look at ATL(Active Template Library). If you are using a visual studio version you will find implementing OLE-based services a breeze with tons of utilities. COM is very easy to implement with ATL. What you're interested in is the CLSID and IID (i.e., Class ID and Interface ID) which are the ones you will use in the CoCreateInstance(...) call.

PROGIDs are utilized if you want to allow the user to pick an object to embed in your application. They wouldn't understand an actual CLSID.

COM is great stuff once you get the hang of it. It really forces you to write better code.

Happy coding.
There are better alternatives to ATL and MFC. WTL (Windows Template Library) is a nice framework to work with; it extends ATL in interesting ways, especially for building UIs and making it easy to make simple games. Also, it's a much simpler framework than MFC, and using / creating COM objects is much simplified with WTL.

-- http://sourceforge.net/projects/wtl/
-- http://www.codeproject.com/wtl/wtl4mfc1.asp


Here is an example on how to mix OpenGL and WTL to build a 3D application using OpenGL.

-- http://www.codeproject.com/wtl/opengl.asp
Thanx lordShade and Anpymous poster(secret:-)),

I will take LordShade advice and try out on learning ATL with COM. I think it will come in handy in later game programming as well. I currently learning on WIN32 version but not the MFC version. So I will get to it after I able to understand the ATL with COM in WIN32 first. Thanx guys .....

p/s:Thanx lessBread the Comp programmer's cookBook really good in MSDN.

learning,
Commy
As a side post, WTL is an extension to ATL for use in windowing. Not really a big deal considering that most of the time a game program will just utilize a single window and have it's own document/view system. Good to look at but I found I rarely use it.

This topic is closed to new replies.

Advertisement