[Prev][Next][Index][Thread]

Re: com and gcc question



When I used to use Microsoft's ATL (Active Template Library,) I was
horrified that the their C++ compiler ommitted COM compatible vtables. 
Vtables are an abstract concept. You should not depend on their
implemntation. 

While I've not studied COM in oskit (I'm mainly a passive lurker on this
list,) I can recommend that you NOT program COM directly in C++.

C++ does, however, provide a good framework for using COM, by having the
COM table as a private table that is referenced from the C++ mothods eg:

class IFoo {
private:
	struct {
		// This table hopefully should be in a COM compatible
		// format. If were going to be pedantic, maybe we should
		// just have an array of pointers in here, and use casts
		// in the main code.

		// Generic COM interface functions.
		HRESULT (*QueryInterface)(...);
		HRESULT (*AddRef)(...);
		HRESULT (*Release)(...);

		// Interface specific functions
		HRESULT (*Foo)(...);
	} * table;
public:
	IFoo() {
		table = CoCreateInstance(/*Whatever*/);
		table->AddRef();
	}

	~IFoo() {
		table->Release();
		table=NULL;
	}

	HRESULT Foo(...) {
		return table->Foo(...);
	}
}

The details of COM are hazy as I haven't touched it for a few years, so
take the details with a pinch of salt. The above framework, however,
should be uniform enough to be generated from a script from an IDL file or
something.

If I've missed something, give me a shout. I've a feeling theres a problem
with this else Microsoft would have implemented it this way in the first 
place:)

Right, rambling over. I'll go back to lurking.

Christian Smith.

On Tue, 21 Sep 1999, Pat Villani wrote:

>I was going through the oskit code and the COM interface.  As a result,
>I thought I'd code in C++ for a small project since COM instantiation is
>supposed to work for both C and C++.  Problems arose when I decided to
>look at the code generated by gcc for a virtual class for COM and found
>that the vtable layout isn't correct.  Checking back with the Microsoft
>spec, it looks like they played the 700 pound gorilla trick and forced
>compiler writers to conform to the "Microsoft Object Model" format in
>order to make COM and C++ compilers work together.
>
>Am I off base with this?  Do I need to write special classes for C++ in
>order to use gcc with the oskit COM objects?   Anyone have any pointers?
>
>Pat
>
>


Follow-Ups: References: