Implementing a COM server with events from an imported type library


2004-11-10 12:11:22 PM
cppbuilder49
Hi,
I was hoping someone could tell me how to make this work. I have to
implement several COM objects that support the same interfaces as well as
fire the same events, so I created a type library with two interfaces, one a
dual interface and the other a DispInterface that defined the events.
When I created my COM server, I added the type library to the Uses list in
the type library for my new COM Object and added the two interfaces to the
CoClass. I then removed the two interfaces that had been put in there at
creation and modified my ones to be the default and they now look like this
[
uuid(4EC1F341-7BB9-4A45-896F-D35C8C45A32F),
version(1.0),
helpstring("TCLProfileServerImplementation Object")
]
coclass TCLProfileServerImplementation
{
[default] interface IProfileServer;
[default, source] dispinterface IProfileServerEvents;
};
But it will not compile, if I try and call one of the Fire_ methods I get an
compiler error saying that the Attach method is not accessible. And there
is a good reason for this, it appears to be missing, I have included the
code from the _TLB.h file from the type library that defines the two
interfaces immediately below. After that I have included code from a _TLB.h
which works, this one didn't have any imported type libraries and anything
fancy at it works.
The code that does not compile as generated:
// *********************************************************************//
// DispIntf: IProfileServerEvents
// Flags: (4096) Dispatchable
// GUID: {FA87F9D7-4987-46E7-AB75-A4AB63EEE345}
// *********************************************************************//
template<class T>
class IProfileServerEventsDispT : public TAutoDriver<IProfileServerEvents>
{
public:
IProfileServerEventsDispT(){}
IProfileServerEventsDispT(IProfileServerEvents *pintf)
{
TAutoDriver<IProfileServerEvents>::Bind(pintf, false);
}
IProfileServerEventsDispT(IProfileServerEventsPtr pintf)
{
TAutoDriver<IProfileServerEvents>::Bind(pintf, true);
}
IProfileServerEventsDispT& operator=(IProfileServerEvents *pintf)
{
TAutoDriver<IProfileServerEvents>::Bind(pintf, false);
return *this;
}
IProfileServerEventsDispT& operator=(IProfileServerEventsPtr pintf)
{
TAutoDriver<IProfileServerEvents>::Bind(pintf, true);
return *this;
}
HRESULT __fastcall
OnProfileChange(Tclprofileserverinterface_tlb::ChangeType Type/*[in]*/
,
Tclprofiledetails_tlb::ITCLProfileUserDetails* Profile/*[in]*/);
HRESULT __fastcall OnError(BSTR Description/*[in]*/);
HRESULT __fastcall OnConnect();
HRESULT __fastcall OnDisconnect(BSTR Reason/*[in]*/);
HRESULT __fastcall OnHouseKeeping();
};
Code from another project that works, spot the difference:
// *********************************************************************//
// DispIntf: ITCLDirectoryClientEvents
// Flags: (4096) Dispatchable
// GUID: {32CC8A3C-9D22-4956-B59D-6091C3F2547A}
// *********************************************************************//
template <class T>
class ITCLDirectoryClientEventsDispT : public
TAutoDriver<ITCLDirectoryClientEvents>
{
public:
ITCLDirectoryClientEventsDispT(){}
void Attach(LPUNKNOWN punk)
{ m_Dispatch = static_cast<T*>(punk); }
HRESULT __fastcall OnClearCompanyCache();
HRESULT __fastcall OnClearPersonalCache();
HRESULT __fastcall OnErrorMessage(BSTR Message/*[in]*/);
HRESULT __fastcall OnDisconnect(BSTR Description/*[in]*/);
HRESULT __fastcall OnConnect();
HRESULT __fastcall
OnReceivedCompanyDirectory(Tcldirclient_tlb::ITCLDirectoryEntries*
Entries/*[in]*/);
HRESULT __fastcall
OnReceivedPersonalDirectory(Tcldirclient_tlb::ITCLDirectoryEntries*
Entries/*[in]*/);
HRESULT __fastcall OnNewTimeStamp(DATE DateTime/*[in]*/);
};
Thanks for your time
Dean