home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / zkuste / vbasic / Data / Utils / XZipComp.exe / XceedWinsock.Cab / F112657_xwlAddressedByteTransferEvents.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-04-18  |  7.4 KB  |  227 lines

  1. unit xwlAddressedByteTransferEvents;
  2.  
  3. {
  4.   Xceed Winsock Library: Delphi supplement file.
  5.   Copyright (c) 2000 Xceed Software Inc.
  6.  
  7.   This file is used to receive dispatch events from the
  8.   AddressedByteTransferEvents class.
  9.  
  10.   This file is part of the Xceed Winsock Library. The source code in
  11.   this file is only intended as a supplement to Xceed Winsock Library's
  12.   documentation, and is provided "as is", without warranty of any kind,
  13.   either expressed or implied.
  14. }
  15.  
  16. interface
  17.  
  18. uses
  19.   XCEEDWINSOCKlib_TLB, Windows, ActiveX;
  20.  
  21. type
  22.  
  23.   IAddressedByteTransferEvents = interface
  24.     { These prototypes were copied from IdXWAddressedByteTransferEvents from
  25.       the Xceed Winsock Library. The disids were removed to transform this
  26.       dispinterface to a standard implementable interface. }
  27.     procedure OnAddressedBytesSent(const xSocket: IDispatch; const xRemoteAddress: IDispatch;
  28.                                    lBytesSent: Integer; lUserParam: Integer; lResultCode: Integer);
  29.     procedure OnAddressedBytesReceived(const xSocket: IDispatch; const xRemoteAddress: IDispatch;
  30.                                        vaData: OleVariant; lUserParam: Integer; lResultCode: Integer);
  31.     procedure OnAddressedBytesAvailable(const xSocket: IDispatch; lBytesReceived: Integer;
  32.                                         lBytesAvailable: Integer);
  33.   end;
  34.  
  35.   TAddressedByteTransferEvents = class( TObject, IUnknown, IDispatch )
  36.   private
  37.     { This is the implementing interface passed at construction }
  38.     m_iCallback : IAddressedByteTransferEvents;
  39.  
  40.     { This is my connection point with the advised event object, and its
  41.       associated cookie }
  42.     m_iConnectionPoint : IConnectionPoint;
  43.     m_lCookie : LongInt;
  44.  
  45.     { IUnknown }
  46.     function QueryInterface( const IID: TGUID; out Obj ) : HResult; stdcall;
  47.     function _AddRef: Integer; stdcall;
  48.     function _Release: Integer; stdcall;
  49.  
  50.     { IDispatch }
  51.     function GetTypeInfoCount( out Count : Integer ) : HResult; stdcall;
  52.     function GetTypeInfo( Index, LocaleID : Integer; out TypeInfo ) : HResult; stdcall;
  53.     function GetIDsOfNames( const IID : TGUID; Names : Pointer;
  54.                             NameCount, LocaleID : Integer; DispIDs : Pointer ) : HResult; stdcall;
  55.     function Invoke( DispID : Integer; const IID : TGUID; LocaleID : Integer;
  56.                      Flags : Word; var Params; VarResult, ExcepInfo, ArgErr : Pointer ) : HResult; stdcall;
  57.   protected
  58.   public
  59.     { Public member exposed for advise with Xceed Winsock Library }
  60.     m_xEventObject : AddressedByteTransferEvents;
  61.  
  62.     { Public methods }
  63.     constructor Create( iImpl : IAddressedByteTransferEvents );
  64.     destructor  Destroy; override;
  65.   end;
  66.  
  67. implementation
  68.  
  69.  
  70. { IUnknown implementation }
  71. function TAddressedByteTransferEvents.QueryInterface( const IID: TGUID; out Obj ) : HResult;
  72. begin
  73.   if GetInterface( IID, Obj ) then
  74.     Result := S_OK
  75.   else if IsEqualIID( IID, IdXWAddressedByteTransferEvents ) then
  76.   begin
  77.     GetInterface( IDispatch, Obj );
  78.     Result := S_OK;
  79.   end
  80.   else
  81.     Result := E_NOINTERFACE;
  82. end;
  83.  
  84. function TAddressedByteTransferEvents._AddRef: Integer;
  85. begin
  86.   { We don't care }
  87.   Result := 1;
  88. end;
  89.  
  90. function TAddressedByteTransferEvents._Release: Integer;
  91. begin
  92.   { We don't care }
  93.   Result := 1;
  94. end;
  95.  
  96. { IDispatch implementation }
  97. function TAddressedByteTransferEvents.GetTypeInfoCount( out Count : Integer ) : HResult;
  98. begin
  99.   { We don't support any type info }
  100.   Count := 0;
  101.   result := S_OK;
  102. end;
  103.  
  104. function TAddressedByteTransferEvents.GetTypeInfo( Index, LocaleID : Integer; out TypeInfo ) : HResult;
  105. begin
  106.   { We don't need to handle this IDispatch method }
  107.   result := E_NOTIMPL;
  108. end;
  109.  
  110. function TAddressedByteTransferEvents.GetIDsOfNames( const IID : TGUID;
  111.                                                   Names : Pointer;
  112.                                                   NameCount, LocaleID : Integer;
  113.                                                   DispIDs : Pointer ) : HResult;
  114. begin
  115.   { We don't need to handle this IDispatch method }
  116.   result := E_NOTIMPL;
  117. end;
  118.  
  119. function TAddressedByteTransferEvents.Invoke( DispID : Integer; const IID : TGUID;
  120.                                            LocaleID : Integer; Flags : Word;
  121.                                            var Params; VarResult, ExcepInfo, ArgErr : Pointer ) : HResult;
  122. var
  123.   xParams : TDispParams;
  124. begin
  125.   if not Assigned( m_iCallback ) then
  126.   begin
  127.     result := E_FAIL;
  128.     Exit;
  129.   end;
  130.   
  131.   { Depending on the DispId, we unmangle parameters and call the proper
  132.     m_iCallback method }
  133.   case DispId of
  134.     100: { OnAddressedBytesSent }
  135.     begin
  136.       xParams := TDispParams( Params );
  137.       if xParams.cArgs <> 5 then
  138.         result := DISP_E_BADPARAMCOUNT
  139.       else
  140.       begin
  141.         m_iCallback.OnAddressedBytesSent( IDispatch( xParams.rgvarg[4].dispVal ),
  142.                                           IDispatch( xParams.rgvarg[3].dispVal ),
  143.                                           xParams.rgvarg[2].lVal,
  144.                                           xParams.rgvarg[1].lVal,
  145.                                           xParams.rgvarg[0].lVal );
  146.         result := S_OK;
  147.       end;
  148.     end;
  149.  
  150.     101: { OnAddressedBytesReceived }
  151.     begin
  152.       xParams := TDispParams( Params );
  153.       if xParams.cArgs <> 5 then
  154.         result := DISP_E_BADPARAMCOUNT
  155.       else
  156.       begin
  157.         m_iCallback.OnAddressedBytesReceived( IDispatch( xParams.rgvarg[4].dispVal ),
  158.                                               IDispatch( xParams.rgvarg[3].dispVal ),
  159.                                               OleVariant( xParams.rgvarg[2] ),
  160.                                               xParams.rgvarg[1].lVal,
  161.                                               xParams.rgvarg[0].lVal );
  162.         result := S_OK;
  163.       end;
  164.     end;
  165.  
  166.     102: { OnAddressedBytesAvailable }
  167.     begin
  168.       xParams := TDispParams( Params );
  169.       if xParams.cArgs <> 3 then
  170.         result := DISP_E_BADPARAMCOUNT
  171.       else
  172.       begin
  173.         m_iCallback.OnAddressedBytesAvailable( IDispatch( xParams.rgvarg[2].dispVal ),
  174.                                                xParams.rgvarg[1].lVal,
  175.                                                xParams.rgvarg[0].lVal );
  176.         result := S_OK;
  177.       end;
  178.     end;
  179.  
  180.     else
  181.       result := DISP_E_MEMBERNOTFOUND;
  182.   end;
  183. end;
  184.  
  185. { Constructor }
  186. constructor TAddressedByteTransferEvents.Create( iImpl : IAddressedByteTransferEvents );
  187. var
  188.   iContainer : IConnectionPointContainer;
  189. begin
  190.   inherited Create;
  191.  
  192.   { Set callback }
  193.   m_iCallback := iImpl;
  194.  
  195.   { Allocate event object }
  196.   m_xEventObject := CoAddressedByteTransferEvents.Create;
  197.  
  198.   { Retrieve its IConnectionPointContainer interface }
  199.   iContainer := m_xEventObject As IConnectionPointContainer;
  200.  
  201.   { Find a connection point with this container }
  202.   iContainer.FindConnectionPoint( IdXWAddressedByteTransferEvents,
  203.                                   m_iConnectionPoint );
  204.  
  205.   if Assigned( m_iConnectionPoint ) then
  206.   begin
  207.     { Advise with this connection point }
  208.     m_iConnectionPoint.Advise( Self As IUnknown, m_lCookie );
  209.   end;
  210. end;
  211.  
  212. { Destructor }
  213. destructor TAddressedByteTransferEvents.Destroy;
  214. begin
  215.   if Assigned( m_iConnectionPoint ) and ( m_lCookie <> 0 )then
  216.     m_iConnectionPoint.Unadvise( m_lCookie );
  217.  
  218.   m_iConnectionPoint := Nil;
  219.   m_xEventObject := Nil;
  220.   m_iCallback := Nil;
  221.  
  222.   inherited Destroy;
  223. end;
  224.  
  225. end.
  226.  
  227.