From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,82871a2f3aa10da8,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-14 17:52:29 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: jaxs@saabsystems.com.au (James) Newsgroups: comp.lang.ada Subject: GNATCOM Thick Bindings (longish) Date: 14 May 2002 17:52:29 -0700 Organization: http://groups.google.com/ Message-ID: <493c4a08.0205141652.500e2a55@posting.google.com> NNTP-Posting-Host: 202.139.137.236 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1021423949 31092 127.0.0.1 (15 May 2002 00:52:29 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 15 May 2002 00:52:29 GMT Xref: archiver1.google.com comp.lang.ada:24062 Date: 2002-05-15T00:52:29+00:00 List-Id: First, thank you to David Botton and ACT for providing GNATCOM! I want to use a GNATCOM generated thick binding to ease the use of an operating system created COM object. My problem is that the Attach procedure in the thick binding appears to call Release on the supplied interface pointer. This decrements the COM objects reference count to zero causing the COM object to be freed. Is there a way to Attach without Releasing? DETAILS ------------------------------------------ I want to encapsulate messages sent/received from external equipment in COM objects. Each object will implement 2 interfaces. The first interface is a custom interface allowing access to the properties of the message (lots of Put_Blah and Get_Blah procedures!). The second interface is IPersistStreamInit allowing the each message to be serialised to an appropriate block of bytes. This will be a sort of Ada.Streams 'Read and 'Write for COM clients. I have a test program that allocates some memory from the heap (GlobalAlloc) and then creates a COM stream interface to that memory (CreateStreamOnHGlobal). I then call the IPersistStreamInit::Save method of my message object to serialise to the heap. Where I run into to trouble is inside my message object's implementation of IPersistStreamInit::Save. I want to use a GNATCOM thick binding to the LPSTREAM parameter of Save but as soon as I call Attach of the thick IStream binding the stream object disappears! Is there a nice way to convince the thick binding to Attach but not to Release the LPSTREAM? CODE ------------------------------------------ function IPersistStreamInit_Save (This : access GNATCOM.Create.COM_Interface.COM_Interface_Type; pstm : Pointer_To_IStream; fClearDirty : Interfaces.C.long) return GNATCOM.Types.HRESULT is type Pointer_To_Byte is access all Base_Byte.Byte; function To_Pointer_To_Unsigned_Char is new Unchecked_Conversion ( Source => Pointer_To_Byte, Target => Messages_BindCOM.Pointer_To_Unsigned_Char); function To_pIStream is new Unchecked_Conversion ( Source => Pointer_To_IStream, Target => Messages_BindCOM.Pointer_To_IStream); Object : Pointer_To_StatusMessage_Type := Pointer_To_StatusMessage_Type (This.CoClass); Message : constant Base_Byte.Byte_String := (1 .. 10 => 16#AA#); -- Not the real message! Message_Length : constant Interfaces.C.Unsigned_Long := Message'Size / 8; Message_Pointer : constant Messages_BindCOM.Pointer_To_Unsigned_Char := To_Pointer_To_Unsigned_Char ( Message (Message'First)'Unrestricted_Access); Stream : Messages_BindCOM.IStream_Interface.IStream_Type; Bytes_Written : aliased Interfaces.C.Unsigned_Long; begin if pstm = null then return GNATCOM.E_POINTER; end if; Messages_BindCOM.IStream_Interface.Initialize (Stream); Messages_BindCOM.IStream_Interface.Attach ( This => Stream, Pointer => To_pIStream (pstm)); -- Kludge fix! --Messages_BindCOM.IStream_Interface.AddRef (Stream); Messages_BindCOM.IStream_Interface.RemoteWrite ( This => Stream, pv => Message_Pointer, cb => Message_Length, pcbWritten => Bytes_Written'Unchecked_Access); if Bytes_Written = Message_Length then if fClearDirty /= GNATCOM.Types.BOOL_FALSE then Object.Modified := False; end if; return GNATCOM.S_OK; else return GNATCOM.E_FAIL; end if; end IPersistStreamInit_Save;