comp.lang.ada
 help / color / mirror / Atom feed
* GNATCOM Thick Bindings (longish)
@ 2002-05-15  0:52 James
  0 siblings, 0 replies; only message in thread
From: James @ 2002-05-15  0:52 UTC (permalink / raw)


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;



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-05-15  0:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-15  0:52 GNATCOM Thick Bindings (longish) James

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox