Difference between revisions of "BinaryStream.Constructor(Handle as Integer, Type as Integer)"

From Xojo Documentation

m
Line 7: Line 7:
 
| platform=all
 
| platform=all
 
}}
 
}}
 
 
{{Description
 
{{Description
 
|text = Creates a [[BinaryStream]] from an OS handle.}}
 
|text = Creates a [[BinaryStream]] from an OS handle.}}
  
 
==Notes==
 
==Notes==
 
 
''Type'' is one of the HandleType class constants and ''Handle'' is the appropriate handle type specified by the ''Type'' parameter.
 
''Type'' is one of the HandleType class constants and ''Handle'' is the appropriate handle type specified by the ''Type'' parameter.
  
Line 36: Line 34:
 
|HandleTypeMacFileSpecPointer
 
|HandleTypeMacFileSpecPointer
 
|An FSSpec (obsolete on Mac OS X. Use HandleTypeMacFileRefNum instead.)
 
|An FSSpec (obsolete on Mac OS X. Use HandleTypeMacFileRefNum instead.)
 
 
|-
 
|-
 
|}
 
|}
Line 42: Line 39:
 
For instance, you can use a [[Declare]] to open a file with whatever permissions that you wish, and then pass the Handle to a stream object's constructor. When you do this, the BinaryStream now retains the ownership rights to the file handle, so you should not close the file handle (via a declare for example), since it will close when the BinaryStream is destructed.
 
For instance, you can use a [[Declare]] to open a file with whatever permissions that you wish, and then pass the Handle to a stream object's constructor. When you do this, the BinaryStream now retains the ownership rights to the file handle, so you should not close the file handle (via a declare for example), since it will close when the BinaryStream is destructed.
  
==Example==
+
== Sample Code ==
 
 
 
<rbcode>
 
<rbcode>
Dim b As New BinaryStream(i, binaryStream.HandleTypeWin32Handle)
+
Dim b As New BinaryStream(i, BinaryStream.HandleTypeWin32Handle)
 
</rbcode>
 
</rbcode>

Revision as of 20:35, 22 January 2019

Constructor

BinaryStream.Constructor(Handle as Integer, Type as Integer)

Creates a BinaryStream from an OS handle.

Notes

Type is one of the HandleType class constants and Handle is the appropriate handle type specified by the Type parameter.

The BinaryStream class constants given below can be passed as the parameter.

Constant Description
HandleTypeWin32Handle A Windows32 OS handle.
HandleTypeFilePointer A file pointer.
HandleTypeFileNumber A file descriptor.
HandleTypeMacFileRefNum A file reference number. (FSRef type)
HandleTypeMacFileSpecPointer An FSSpec (obsolete on Mac OS X. Use HandleTypeMacFileRefNum instead.)

For instance, you can use a Declare to open a file with whatever permissions that you wish, and then pass the Handle to a stream object's constructor. When you do this, the BinaryStream now retains the ownership rights to the file handle, so you should not close the file handle (via a declare for example), since it will close when the BinaryStream is destructed.

Sample Code

Dim b As New BinaryStream(i, BinaryStream.HandleTypeWin32Handle)