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

  1. unit xwlStringTransferEvents;
  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.   StringTransferEvents 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.   IStringTransferEvents = interface
  24.     { These prototypes were copied from IdXWStringTransferEvents from
  25.       the Xceed Winsock Library. The disids were removed to transform this
  26.       dispinterface to a standard implementable interface. }
  27.     procedure OnStringSent( const xSocket : IDispatch;
  28.                             lUserParam : Integer;
  29.                             lResultCode : Integer );
  30.     procedure OnStringReceived( const xSocket : IDispatch;
  31.                                 const sString : WideString;
  32.                                 lUserParam : Integer;
  33.                                 lResultCode: Integer );
  34.     procedure OnStringAvailable( const xSocket : IDispatch;
  35.                                  lCharsReceived : Integer;
  36.                                  lCharsAvailable : Integer );
  37.     procedure OnOutOfBandStringReceived( const xSocket: IDispatch;
  38.                                          const sString: WideString;
  39.                                          lResultCode: Integer );
  40.   end;
  41.  
  42.   TStringTransferEvents = class( TObject, IUnknown, IDispatch )
  43.   private
  44.     { This is the implementing interface passed at construction }
  45.     m_iCallback : IStringTransferEvents;
  46.  
  47.     { This is my connection point with the advised event object, and its
  48.       associated cookie }
  49.     m_iConnectionPoint : IConnectionPoint;
  50.     m_lCookie : LongInt;
  51.  
  52.     { IUnknown }
  53.     function QueryInterface( const IID: TGUID; out Obj ) : HResult; stdcall;
  54.     function _AddRef: Integer; stdcall;
  55.     function _Release: Integer; stdcall;
  56.  
  57.     { IDispatch }
  58.     function GetTypeInfoCount( out Count : Integer ) : HResult; stdcall;
  59.     function GetTypeInfo( Index, LocaleID : Integer; out TypeInfo ) : HResult; stdcall;
  60.     function GetIDsOfNames( const IID : TGUID; Names : Pointer;
  61.                             NameCount, LocaleID : Integer; DispIDs : Pointer ) : HResult; stdcall;
  62.     function Invoke( DispID : Integer; const IID : TGUID; LocaleID : Integer;
  63.                      Flags : Word; var Params; VarResult, ExcepInfo, ArgErr : Pointer ) : HResult; stdcall;
  64.   protected
  65.   public
  66.     { Public member exposed for advise with Xceed Winsock Library }
  67.     m_xEventObject : StringTransferEvents;
  68.  
  69.     { Public methods }
  70.     constructor Create( iImpl : IStringTransferEvents );
  71.     destructor  Destroy; override;
  72.   end;
  73.  
  74. implementation
  75.  
  76.  
  77. { IUnknown implementation }
  78. function TStringTransferEvents.QueryInterface( const IID: TGUID; out Obj ) : HResult;
  79. begin
  80.   if GetInterface( IID, Obj ) then
  81.     Result := S_OK
  82.   else if IsEqualIID( IID, IdXWStringTransferEvents ) then
  83.   begin
  84.     GetInterface( IDispatch, Obj );
  85.     Result := S_OK;
  86.   end
  87.   else
  88.     Result := E_NOINTERFACE;
  89. end;
  90.  
  91. function TStringTransferEvents._AddRef: Integer;
  92. begin
  93.   { We don't care }
  94.   Result := 1;
  95. end;
  96.  
  97. function TStringTransferEvents._Release: Integer;
  98. begin
  99.   { We don't care }
  100.   Result := 1;
  101. end;
  102.  
  103. { IDispatch implementation }
  104. function TStringTransferEvents.GetTypeInfoCount( out Count : Integer ) : HResult;
  105. begin
  106.   { We don't support any type info }
  107.   Count := 0;
  108.   result := S_OK;
  109. end;
  110.  
  111. function TStringTransferEvents.GetTypeInfo( Index, LocaleID : Integer; out TypeInfo ) : HResult;
  112. begin
  113.   { We don't need to handle this IDispatch method }
  114.   result := E_NOTIMPL;
  115. end;
  116.  
  117. function TStringTransferEvents.GetIDsOfNames( const IID : TGUID;
  118.                                                   Names : Pointer;
  119.                                                   NameCount, LocaleID : Integer;
  120.                                                   DispIDs : Pointer ) : HResult;
  121. begin
  122.   { We don't need to handle this IDispatch method }
  123.   result := E_NOTIMPL;
  124. end;
  125.  
  126. function TStringTransferEvents.Invoke( DispID : Integer; const IID : TGUID;
  127.                                            LocaleID : Integer; Flags : Word;
  128.                                            var Params; VarResult, ExcepInfo, ArgErr : Pointer ) : HResult;
  129. var
  130.   xParams : TDispParams;
  131. begin
  132.   { Depending on the DispId, we unmangle parameters and call the proper
  133.     m_iCallback method }
  134.   case DispId of
  135.     100: { OnStringSent }
  136.     begin
  137.       xParams := TDispParams( Params );
  138.       if xParams.cArgs <> 3 then
  139.         result := DISP_E_BADPARAMCOUNT
  140.       else
  141.       begin
  142.         m_iCallback.OnStringSent( IDispatch( xParams.rgvarg[2].dispVal ),
  143.                                   xParams.rgvarg[1].lVal,
  144.                                   xParams.rgvarg[0].lVal );
  145.         result := S_OK;
  146.       end;
  147.     end;
  148.  
  149.     101: { OnStringReceived }
  150.     begin
  151.       xParams := TDispParams( Params );
  152.       if xParams.cArgs <> 4 then
  153.         result := DISP_E_BADPARAMCOUNT
  154.       else
  155.       begin
  156.         m_iCallback.OnStringReceived( IDispatch( xParams.rgvarg[3].dispVal ),
  157.                                       WideString( xParams.rgvarg[2].bstrVal ),
  158.                                       xParams.rgvarg[1].lVal,
  159.                                       xParams.rgvarg[0].lVal );
  160.         result := S_OK;
  161.       end;
  162.     end;
  163.  
  164.     102: { OnStringAvailable }
  165.     begin
  166.       xParams := TDispParams( Params );
  167.       if xParams.cArgs <> 3 then
  168.         result := DISP_E_BADPARAMCOUNT
  169.       else
  170.       begin
  171.         m_iCallback.OnStringAvailable( IDispatch( xParams.rgvarg[2].dispVal ),
  172.                                        xParams.rgvarg[1].lVal,
  173.                                        xParams.rgvarg[0].lVal );
  174.         result := S_OK;
  175.       end;
  176.     end;
  177.  
  178.     103: { OnOutOfBandStringReceived }
  179.     begin
  180.       xParams := TDispParams( Params );
  181.       if xParams.cArgs <> 3 then
  182.         result := DISP_E_BADPARAMCOUNT
  183.       else
  184.       begin
  185.         m_iCallback.OnOutOfBandStringReceived( IDispatch( xParams.rgvarg[2].dispVal ),
  186.                                                WideString( xParams.rgvarg[1].bstrVal ),
  187.                                                xParams.rgvarg[0].lVal );
  188.         result := S_OK;
  189.       end;
  190.     end;
  191.  
  192.     else
  193.       result := DISP_E_MEMBERNOTFOUND;
  194.   end;
  195. end;
  196.  
  197. { Constructor }
  198. constructor TStringTransferEvents.Create( iImpl : IStringTransferEvents );
  199. var
  200.   iContainer : IConnectionPointContainer;
  201. begin
  202.   inherited Create;
  203.  
  204.   { Set callback }
  205.   m_iCallback := iImpl;
  206.  
  207.   { Allocate event object }
  208.   m_xEventObject := CoStringTransferEvents.Create;
  209.  
  210.   { Retrieve its IConnectionPointContainer interface }
  211.   iContainer := m_xEventObject As IConnectionPointContainer;
  212.  
  213.   { Find a connection point with this container }
  214.   iContainer.FindConnectionPoint( IdXWStringTransferEvents,
  215.                                   m_iConnectionPoint );
  216.  
  217.   if Assigned( m_iConnectionPoint ) then
  218.   begin
  219.     { Advise with this connection point }
  220.     m_iConnectionPoint.Advise( Self As IUnknown, m_lCookie );
  221.   end;
  222. end;
  223.  
  224. { Destructor }
  225. destructor TStringTransferEvents.Destroy;
  226. begin
  227.   if Assigned( m_iConnectionPoint ) and ( m_lCookie <> 0 )then
  228.     m_iConnectionPoint.Unadvise( m_lCookie );
  229.  
  230.   m_iConnectionPoint := Nil;
  231.   m_xEventObject := Nil;
  232.   m_iCallback := Nil;
  233.  
  234.   inherited Destroy;
  235. end;
  236.  
  237. end.
  238.  
  239.