浏览代码

+ basic TStreamAdapter implementation

git-svn-id: trunk@7815 -
florian 18 年之前
父节点
当前提交
0caa70a8b3
共有 3 个文件被更改,包括 100 次插入13 次删除
  1. 6 4
      packages/base/winunits/activex.pp
  2. 83 0
      rtl/objpas/classes/streams.inc
  3. 11 9
      rtl/objpas/types.pp

+ 6 - 4
packages/base/winunits/activex.pp

@@ -1521,7 +1521,7 @@ TYPE
 
 // Forward interfaces.
 
-   IStream             = Interface;
+   IStream             = Types.IStream;
    IMoniker            = Interface;
    IEnumMoniker        = Interface;
    IEnumString         = Interface;
@@ -1745,13 +1745,15 @@ TYPE
        Function Clone(Out penum:IEnumString):HResult;StdCall;
        End;
 
-    ISequentialStream = interface(IUnknown)
+    ISequentialStream = Types.ISequentialStream;
+    {interface(IUnknown)
        ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
        function Read(pv : Pointer;cb : ULONG;pcbRead : PULONG) : HRESULT;stdcall;
        function Write(pv : Pointer;cb : ULONG;pcbWritten : PULONG): HRESULT;stdcall;
      end;
+    }
 
-    IStream = interface(ISequentialStream)
+    { defined above by pulling it in from types IStream = interface(ISequentialStream)
        ['{0000000C-0000-0000-C000-000000000046}']
        function Seek(dlibMove : LargeInt; dwOrigin: Longint;
             out libNewPosition : LargeInt): HResult; stdcall;
@@ -1767,7 +1769,7 @@ TYPE
        Function Stat(out statstg : TStatStg; grfStatFlag: Longint): HRESULT;stdcall;
        function Clone(out stm : IStream) : HRESULT; stdcall;
      end;
-
+    }
     IEnumSTATSTG = Interface (IUnknown)
        ['{0000000d-0000-0000-C000-000000000046}']
         Function Next (Celt:ULong;Out xcelt;pceltfetched : PUlong):HResult; StdCall;

+ 83 - 0
rtl/objpas/classes/streams.inc

@@ -785,3 +785,86 @@ begin
   inherited Destroy;
 end;
 
+{****************************************************************************}
+{*                             TStreamAdapter                               *}
+{****************************************************************************}
+constructor TStreamAdapter.Create(Stream: TStream; Ownership: TStreamOwnership = soReference);
+begin
+  inherited Create;
+  FStream:=Stream;
+  FOwnership:=Ownership;
+end;
+
+
+destructor TStreamAdapter.Destroy;
+begin
+  if StreamOwnership=soOwned then
+    FreeAndNil(FStream);
+  inherited Destroy;
+end;
+  
+  
+function TStreamAdapter.Read(pv: Pointer; cb: DWORD; pcbRead: PDWORD): HResult; stdcall;
+begin
+  runerror(217);
+end;
+
+
+function TStreamAdapter.Write(pv: Pointer; cb: DWORD; pcbWritten: PDWORD): HResult; stdcall;
+begin
+  runerror(217);
+end;
+
+
+function TStreamAdapter.Seek(dlibMove: Largeint; dwOrigin: Longint; out libNewPosition: Largeint): HResult; stdcall;
+begin
+  runerror(217);
+end;
+
+
+function TStreamAdapter.SetSize(libNewSize: Largeint): HResult; stdcall;
+begin
+  runerror(217);
+end;
+
+
+function TStreamAdapter.CopyTo(stm: IStream; cb: Largeint; out cbRead: Largeint; out cbWritten: Largeint): HResult; stdcall;
+begin
+  runerror(217);
+end;
+
+
+function TStreamAdapter.Commit(grfCommitFlags: Longint): HResult; stdcall;
+begin
+  runerror(217);
+end;
+
+
+function TStreamAdapter.Revert: HResult; stdcall;
+begin
+  runerror(217);
+end;
+
+
+function TStreamAdapter.LockRegion(libOffset: Largeint; cb: Largeint; dwLockType: Longint): HResult; stdcall;
+begin
+  runerror(217);
+end;
+
+
+function TStreamAdapter.UnlockRegion(libOffset: Largeint; cb: Largeint; dwLockType: Longint): HResult; stdcall;
+begin
+  runerror(217);
+end;
+
+
+function TStreamAdapter.Stat(out statstg: TStatStg; grfStatFlag: Longint): HResult; stdcall;
+begin
+  runerror(217);
+end;
+
+
+function TStreamAdapter.Clone(out stm: IStream): HResult; stdcall;
+begin
+  runerror(217);
+end;

+ 11 - 9
rtl/objpas/types.pp

@@ -216,6 +216,9 @@ type
   FILETIME = _FILETIME;
   PFileTime = ^TFileTime;
 
+{$endif Windows}
+
+type
   tagSTATSTG =
 {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
   packed
@@ -236,19 +239,19 @@ type
   TStatStg = tagSTATSTG;
   STATSTG = TStatStg;
   PStatStg = ^TStatStg;
-
+  
+  { classes depends on these interfaces, we can't use the activex unit in classes though }  
   IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
      Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
      Function LockServer(fLock : LongBool) : HResult;StdCall;
   End;
 
-    ISequentialStream = interface(IUnknown)
-       ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
-       function Read(pv : Pointer;cb : DWORD;pcbRead : PDWORD) : HRESULT;stdcall;
-       function Write(pv : Pointer;cb : DWORD;pcbWritten : PDWORD): HRESULT;stdcall;
-     end;
-
-
+  ISequentialStream = interface(IUnknown)
+     ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
+     function Read(pv : Pointer;cb : DWORD;pcbRead : PDWORD) : HRESULT;stdcall;
+     function Write(pv : Pointer;cb : DWORD;pcbWritten : PDWORD): HRESULT;stdcall;
+  end;
+  
   IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
      function Seek(dlibMove : LargeInt; dwOrigin : Longint;
        out libNewPosition : LargeInt) : HResult;stdcall;
@@ -264,7 +267,6 @@ type
      Function Stat(out statstg : TStatStg;grfStatFlag : Longint) : HRESULT;stdcall;
      function Clone(out stm : IStream) : HRESULT;stdcall;
   end;
-{$endif Windows}
 
 function EqualRect(const r1,r2 : TRect) : Boolean;
 function Rect(Left,Top,Right,Bottom : Integer) : TRect;