The question about how to implement abstract class in COM
-
For example i got next architecture:
class BaseClass
{
virtual void Method1();
virtual void Method2();
};class FuncClassOne: public BaseClass
{
void Method1();
void Method2();
};
class FuncClassTwo: public BaseClass
{
void Method1();
void Method2();
};
class Grup
{
BaseClass** m_ppObjects;
void CallAllMethods();
void Add(BaseClass* pBaseClass);
BaseClass* GetObject(long ObjectID);
};So, i want to save this architecture and place everything in COM; Let me try to explaint what i need (I imagine ):
IGrupPtr group(CLSID_Grup); //I hope to see it as interface
for(int i = 0;i<10;i++)
{
IFuncClassOnePtr p(CLSID_FuncClassOne); //I hope to see it as interface
group->Add(p);
}for(int i = 0;i<10;i++)
{
IFuncClassTwoPtr p(CLSID_FuncClassTwo); //I hope to see it as interface
group->Add(p);
}
group->CallAllMethods();BaseClass* pClass = group->GetObject(7); So how can i make frome every class COM Interface? Is it possible? Or i need to choose another way???
-
For example i got next architecture:
class BaseClass
{
virtual void Method1();
virtual void Method2();
};class FuncClassOne: public BaseClass
{
void Method1();
void Method2();
};
class FuncClassTwo: public BaseClass
{
void Method1();
void Method2();
};
class Grup
{
BaseClass** m_ppObjects;
void CallAllMethods();
void Add(BaseClass* pBaseClass);
BaseClass* GetObject(long ObjectID);
};So, i want to save this architecture and place everything in COM; Let me try to explaint what i need (I imagine ):
IGrupPtr group(CLSID_Grup); //I hope to see it as interface
for(int i = 0;i<10;i++)
{
IFuncClassOnePtr p(CLSID_FuncClassOne); //I hope to see it as interface
group->Add(p);
}for(int i = 0;i<10;i++)
{
IFuncClassTwoPtr p(CLSID_FuncClassTwo); //I hope to see it as interface
group->Add(p);
}
group->CallAllMethods();BaseClass* pClass = group->GetObject(7); So how can i make frome every class COM Interface? Is it possible? Or i need to choose another way???
Their is quite alot of things that go into making a COM object, however to set you in the right direction: 1. your 2 interfaces I am assuming will be FuncClassOne and FuncClassTwo. To do that you need to define them as such (BTW all COM interfaces derive from IUnknown)
interface FuncClassOne : IUnknown
{
virtual void __stdcall Method1() = 0;
virtual void __stdcall Method2() = 0;
}
interface FuncClassTwo : IUnknown
{
virtual void __stdcall fc2_Method1() = 0;
virtual void __stdcall fc2_Method2() = 0;
}2. Now you will need your COM object, containing your interfaces and the implementations.
class FuncClass : public FuncClassOne,
public FuncClassTwo
{
public:
//every COM object needs to implement these 3 functions
virtual HRESULT __stdcall QueryInterface(REFIID iid, void** ppv);
virtual ULONG __stdcall AddRef();
virtual ULONG __stdcall Release();
//now implement your functions
virtual void __stdcall Method1();
virtual void __stdcall Method2();
virtual void __stdcall fc2_Method1();
virtual void __stdcall fc2_Method2();
//std class stuff
FuncClass();
~FuncClass();
private:
long m_cRef;
};3. Now you need to implement your COM functions This was really just so you could see the COM implementation in C++ for what you were asking (At least I hope it was what you were asking). You really should look on MSDN for what is required to implement the COM functions and how to create CLSIDs and register your component. Unfortunately the topic is just too large to be answered fully, on this post. I hope I at least got you going in the right direction and knowing what to look for now.
-
Their is quite alot of things that go into making a COM object, however to set you in the right direction: 1. your 2 interfaces I am assuming will be FuncClassOne and FuncClassTwo. To do that you need to define them as such (BTW all COM interfaces derive from IUnknown)
interface FuncClassOne : IUnknown
{
virtual void __stdcall Method1() = 0;
virtual void __stdcall Method2() = 0;
}
interface FuncClassTwo : IUnknown
{
virtual void __stdcall fc2_Method1() = 0;
virtual void __stdcall fc2_Method2() = 0;
}2. Now you will need your COM object, containing your interfaces and the implementations.
class FuncClass : public FuncClassOne,
public FuncClassTwo
{
public:
//every COM object needs to implement these 3 functions
virtual HRESULT __stdcall QueryInterface(REFIID iid, void** ppv);
virtual ULONG __stdcall AddRef();
virtual ULONG __stdcall Release();
//now implement your functions
virtual void __stdcall Method1();
virtual void __stdcall Method2();
virtual void __stdcall fc2_Method1();
virtual void __stdcall fc2_Method2();
//std class stuff
FuncClass();
~FuncClass();
private:
long m_cRef;
};3. Now you need to implement your COM functions This was really just so you could see the COM implementation in C++ for what you were asking (At least I hope it was what you were asking). You really should look on MSDN for what is required to implement the COM functions and how to create CLSIDs and register your component. Unfortunately the topic is just too large to be answered fully, on this post. I hope I at least got you going in the right direction and knowing what to look for now.
Thank you for participating i tried to do something like you show me: So I made an ATL Project, and in the midle file i wrote next thing: [ object, uuid(BFBF8B9C-64BF-42bc-82D5-8564B637012B), dual, nonextensible, helpstring("IAbstractGeoObject Interface"), pointer_default(unique) ] interface IAbstractGeoObject : IDispatch { [id(1), helpstring("method Draw")] virtual HRESULT Draw() = 0; } [ object, uuid(16578C15-F715-4A3A-94E7-70C1387A53B7), dual, nonextensible, helpstring("IGeoObject Interface"), pointer_default(unique) ] interface IGeoObject : IAbstractGeoObject{ [id(1), helpstring("method Draw")] HRESULT Draw(void); }; But it doesn't want to compile it... It shows next error message: "Expecting a type specification near "virtual""... So i'm in the dead end...