Board index » cppbuilder » Returning a Delphi interface from a C++ class implementing it
OBones
CBuilder Developer |
Returning a Delphi interface from a C++ class implementing it2006-08-10 04:30:23 AM cppbuilder48 Hi all, Once again, I know this forum is not for technical questions, but I could not find one that matches the area I'm looking at. If you figure out a best place, please tell me. Anyway, here is my new problem: I'm getting an access violation (access to 000000) in this code: static _di_INewService __fastcall Create() { _di_INewService result; TNewService_Proxy* proxy = new TNewService_Proxy(); if (proxy->QueryInterface(INewService_IID, result)) return result; }; The AV occurs on the call to QueryInterface. I don't understand why this happens and sincerely hope someone can help. You will find the declarations for _di_INewService and TNewService_Proxy at the end of this message and were inspired by what dcc32 does when generating the hpp file from a pascal file. Note that the interface and class MUST be compatible with the delphi ones because they will be passed to functions in delphi units. Once again, many thanks for any help. Olivier Sannier __interface INewService; typedef System::DelphiInterface<INewService>_di_INewService; __interface INTERFACE_UUID("{3D581A93-D126-49DB-82BA-5EF7818657BC}") INewService : public IInterface { public: virtual int __fastcall Sum( const int A, const int B ) = 0; // pure virtual function - interface only virtual TDateTime __fastcall GetServerTime( ) = 0; // pure virtual function - interface only }; class DELPHICLASS TNewService_Proxy; class TNewService_Proxy : public TROProxy { typedef TROProxy inherited; protected: virtual AnsiString __fastcall __GetInterfaceName() { return "NewService"; } virtual int __fastcall Sum( const int A, const int B ); virtual TDateTime __fastcall GetServerTime( ); public: #pragma option push -w-inl /* TROProxy.Create */ inline __fastcall virtual TNewService_Proxy(const Uroclientintf::_di_IROMessage aMessage, const Uroclientintf::_di_IROTransportChannel aTransportChannel)/* overload */ : TROProxy(aMessage, aTransportChannel) {} #pragma option pop public: #pragma option push -w-inl /* TObject.Destroy */ inline __fastcall virtual ~TNewService_Proxy() {} #pragma option pop private: void *__INewService; /* NewLibrary_Intf_intf::INewService */ public: operator INewService*() { return (INewService*)&__INewService; } }; |