dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
May 19, 2001

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


ReadFromStdInput - Read from standard input stream

Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) _
    As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, _
    lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, _
    lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long

Private Const STD_INPUT_HANDLE = -10&

' read a number of chars from standard input channel
'
' if NumBytes < 0 then it reads all the bytes
' from the standard input
'
' NOTE: this routine works only in compiled applications

Function ReadFromStdInput(Optional ByVal NumBytes As Long = -1) As String
    Dim hStdIn As Long
    Dim ret As Long
    Dim buffer As String
    Dim bytesRead As Long
    
    ' get the handle of standard input
    hStdIn = GetStdHandle(STD_INPUT_HANDLE)
    
    ' prepare receiving buffer
    buffer = Space$(1024)
    
    Do
        ' read from standard input
        ret = ReadFile(hStdIn, ByVal buffer, Len(buffer), bytesRead, ByVal 0&)
    
        ' deal with errors
        If ret = 0 Then
            Err.Raise 1001, , "Unable to read from standard input"
        End If
        
        ' append to result built so far
        ReadFromStdInput = ReadFromStdInput & Left$(buffer, bytesRead)
        
        ' continue to read if there are more chars
    Loop Until bytesRead < Len(buffer)
        
End Function
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date