home *** CD-ROM | disk | FTP | other *** search
- unit xwlFileTransferEvents;
-
- {
- Xceed Winsock Library: Delphi supplement file.
- Copyright (c) 2000 Xceed Software Inc.
-
- This file is used to receive dispatch events from the
- FileTransferEvents class.
-
- This file is part of the Xceed Winsock Library. The source code in
- this file is only intended as a supplement to Xceed Winsock Library's
- documentation, and is provided "as is", without warranty of any kind,
- either expressed or implied.
- }
-
- interface
-
- uses
- XCEEDWINSOCKlib_TLB, Windows, ActiveX;
-
- type
-
- IFileTransferEvents = interface
- { These prototypes were copied from IdXWFileTransferEvents from
- the Xceed Winsock Library. The disids were removed to transform this
- dispinterface to a standard implementable interface. }
- procedure OnFileSent( const xSocket : IDispatch;
- const sFilename : WideString;
- lStartOffset : Integer;
- lBytesSent : Integer;
- lBytesTotal : Integer;
- lUserParam : Integer;
- bTransferCompleted : WordBool;
- lResultCode: Integer );
- procedure OnFileReceived( const xSocket : IDispatch;
- const sFilename : WideString;
- lStartOffset : Integer;
- lBytesReceived : Integer;
- lBytesTotal : Integer;
- lUserParam : Integer;
- bTransferCompleted : WordBool;
- lResultCode : Integer );
- end;
-
- TFileTransferEvents = class( TObject, IUnknown, IDispatch )
- private
- { This is the implementing interface passed at construction }
- m_iCallback : IFileTransferEvents;
-
- { This is my connection point with the advised event object, and its
- associated cookie }
- m_iConnectionPoint : IConnectionPoint;
- m_lCookie : LongInt;
-
- { IUnknown }
- function QueryInterface( const IID: TGUID; out Obj ) : HResult; stdcall;
- function _AddRef: Integer; stdcall;
- function _Release: Integer; stdcall;
-
- { IDispatch }
- function GetTypeInfoCount( out Count : Integer ) : HResult; stdcall;
- function GetTypeInfo( Index, LocaleID : Integer; out TypeInfo ) : HResult; stdcall;
- function GetIDsOfNames( const IID : TGUID; Names : Pointer;
- NameCount, LocaleID : Integer; DispIDs : Pointer ) : HResult; stdcall;
- function Invoke( DispID : Integer; const IID : TGUID; LocaleID : Integer;
- Flags : Word; var Params; VarResult, ExcepInfo, ArgErr : Pointer ) : HResult; stdcall;
- protected
- public
- { Public member exposed for advise with Xceed Winsock Library }
- m_xEventObject : FileTransferEvents;
-
- { Public methods }
- constructor Create( iImpl : IFileTransferEvents );
- destructor Destroy; override;
- end;
-
- implementation
-
-
- { IUnknown implementation }
- function TFileTransferEvents.QueryInterface( const IID: TGUID; out Obj ) : HResult;
- begin
- if GetInterface( IID, Obj ) then
- Result := S_OK
- else if IsEqualIID( IID, IdXWFileTransferEvents ) then
- begin
- GetInterface( IDispatch, Obj );
- Result := S_OK;
- end
- else
- Result := E_NOINTERFACE;
- end;
-
- function TFileTransferEvents._AddRef: Integer;
- begin
- { We don't care }
- Result := 1;
- end;
-
- function TFileTransferEvents._Release: Integer;
- begin
- { We don't care }
- Result := 1;
- end;
-
- { IDispatch implementation }
- function TFileTransferEvents.GetTypeInfoCount( out Count : Integer ) : HResult;
- begin
- { We don't support any type info }
- Count := 0;
- result := S_OK;
- end;
-
- function TFileTransferEvents.GetTypeInfo( Index, LocaleID : Integer; out TypeInfo ) : HResult;
- begin
- { We don't need to handle this IDispatch method }
- result := E_NOTIMPL;
- end;
-
- function TFileTransferEvents.GetIDsOfNames( const IID : TGUID;
- Names : Pointer;
- NameCount, LocaleID : Integer;
- DispIDs : Pointer ) : HResult;
- begin
- { We don't need to handle this IDispatch method }
- result := E_NOTIMPL;
- end;
-
- function TFileTransferEvents.Invoke( DispID : Integer; const IID : TGUID;
- LocaleID : Integer; Flags : Word;
- var Params; VarResult, ExcepInfo, ArgErr : Pointer ) : HResult;
- var
- xParams : TDispParams;
- begin
- { Depending on the DispId, we unmangle parameters and call the proper
- m_iCallback method }
- case DispId of
- 100: { OnFileSent }
- begin
- xParams := TDispParams( Params );
- if xParams.cArgs <> 8 then
- result := DISP_E_BADPARAMCOUNT
- else
- begin
- m_iCallback.OnFileSent( IDispatch( xParams.rgvarg[7].dispVal ),
- WideString( xParams.rgvarg[6].bstrVal ),
- xParams.rgvarg[5].lVal,
- xParams.rgvarg[4].lVal,
- xParams.rgvarg[3].lVal,
- xParams.rgvarg[2].lVal,
- xParams.rgvarg[1].vbool,
- xParams.rgvarg[0].lVal );
- result := S_OK;
- end;
- end;
-
- 101: { OnFileReceived }
- begin
- xParams := TDispParams( Params );
- if xParams.cArgs <> 8 then
- result := DISP_E_BADPARAMCOUNT
- else
- begin
- m_iCallback.OnFileReceived( IDispatch( xParams.rgvarg[7].dispVal ),
- WideString( xParams.rgvarg[6].bstrVal ),
- xParams.rgvarg[5].lVal,
- xParams.rgvarg[4].lVal,
- xParams.rgvarg[3].lVal,
- xParams.rgvarg[2].lVal,
- xParams.rgvarg[1].vbool,
- xParams.rgvarg[0].lVal );
- result := S_OK;
- end;
- end;
-
- else
- result := DISP_E_MEMBERNOTFOUND;
- end;
- end;
-
- { Constructor }
- constructor TFileTransferEvents.Create( iImpl : IFileTransferEvents );
- var
- iContainer : IConnectionPointContainer;
- begin
- inherited Create;
-
- { Set callback }
- m_iCallback := iImpl;
-
- { Allocate event object }
- m_xEventObject := CoFileTransferEvents.Create;
-
- { Retrieve its IConnectionPointContainer interface }
- iContainer := m_xEventObject As IConnectionPointContainer;
-
- { Find a connection point with this container }
- iContainer.FindConnectionPoint( IdXWFileTransferEvents,
- m_iConnectionPoint );
-
- if Assigned( m_iConnectionPoint ) then
- begin
- { Advise with this connection point }
- m_iConnectionPoint.Advise( Self As IUnknown, m_lCookie );
- end;
- end;
-
- { Destructor }
- destructor TFileTransferEvents.Destroy;
- begin
- if Assigned( m_iConnectionPoint ) and ( m_lCookie <> 0 )then
- m_iConnectionPoint.Unadvise( m_lCookie );
-
- m_iConnectionPoint := Nil;
- m_xEventObject := Nil;
- m_iCallback := Nil;
-
- inherited Destroy;
- end;
-
- end.
-
-