Board index » cppbuilder » Using delphi interfaces in C++
OBones
![]() CBuilder Developer |
Using delphi interfaces in C++2006-08-11 04:40:32 PM cppbuilder41 Hi all, Still struggling with interfaces but this time they are declared and defined in a Delphi file, I'm simply using the generated HPP file but am getting acces violations or privileged instructions. Here is what I did: I dropped two components on my Form, namely a TROBinMessage and a TROSuperTcpChannel. These classes implement a few interfaces, namely these: TROBinMessage IROBinMessage, IROStreamAccess implemented in parent class, TROMessage IUnknown, IROMessage, IROMessageCloneable, IROModuleInfo TROSuperTCPChannel IROTransport, IROTCPTransport, IROActiveEventChannel, IROMultiThreadAwareChannel, IROAsyncTransportChannel, IROActiveAsyncTransportChannel, IROTransportChannelEx implemented in parent class, TROTransportChannel IROTransportChannel, IROTransport, IROMetadataReader In my C++ code, I want to use InitializeRequestMessage and Write defined in IROMessage like this: virtual void __fastcall InitializeRequestMessage( const _di_IROTransport aTransport, const AnsiString aLibraryName, const AnsiString anInterfaceName, const AnsiString aMessageName) = 0 ; virtual void __fastcall Write(const AnsiString aName, Typinfo::PTypeInfo aTypeInfo, const void *Ptr, TParamAttributes ExtraAttributes) = 0 ; and so I wrote the following code in C++: _di_IROMessage __Message = ROBinMessage1->operator IROMessage *(); _di_IROTransport __Transport = ROSuperTcpChannel1->operator IROTransport *(); AnsiString __InterfaceName = "NewService"; int A = 1; __Message->InitializeRequestMessage(__Transport, "NewLibrary", __InterfaceName, "Sum"); __Message->Write("A", __GetintInfo, &A, TParamAttributes()); __GetintInfo is a #define that expands to a function call that returns the type infos taken from a published property of type int. When I run this code, I'm getting an access violation error on the call to InitializeRequestMessage. I tried to trace it, it triggers the error in System.pas apparently while creating the strings to pass to the method (_LStrFromPChar and _LStrFromPCharLen). I really don't understand what's wrong here and am even more puzzled when the same code in Delphi works just fine: var __Message: IROMessage; __Transport: IROTransport; __InterfaceName: string; A: Integer; begin if not ROSuperTcpChannel1.Connected then ROSuperTcpChannel1.Active := true; __Message := ROBinMessage1; __Transport := ROSuperTcpChannel1; __InterfaceName := 'NewService'; A := 1; __Message.InitializeRequestMessage(__Transport, 'NewLibrary', __InterfaceName, 'Sum'); __Message.Write('A', TypeInfo(Integer), A, []); end; Any help would be VERY much appreciated. Cheers Olivier |