Why do I get error 6 (The Handle is Invalid) trying to WriteFile to STDOUT from VB 6 exe?
- From: "Grant Schenck" <schenckg@xxxxxxxxxxxxx>
- Date: Thu, 26 Oct 2006 10:34:15 -0400
Hello,
- I create the following VB 6 app to write to STDOUT (the console).
- I build it into an exe.
- I run the exe from a command line.
- I get no output and my code detects a WriteFile failure with an underlying
result code of 6, Invalid handle.
The handle I get back from GetStdHandle(STD_OUTPUT_HANDLE) is 7 which I
believe is valid.
I'm assuming somehow my vb app can't see the console it is being run from.
I'd expect this failure running from the IDE but not from the command line.
What is the story? I checked the web and this seems like the right way to
write to the console. What am I missing???
-------------------------------------------------------
Public Const STD_OUTPUT_HANDLE = -11&
Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As
Long
Private Declare Function WriteFile Lib "kernel32" _
(ByVal hFile As Long, _
ByVal lpBuffer As Any, _
ByVal nNumberOfBytesToWrite As Long, _
lpNumberOfBytesWritten As Long, _
ByVal lpOverlapped As Any) As Long
Sub Out(ByVal strOut As String)
' Sends data to StdOut stream
Dim lHandle As Long
lHandle = GetStdHandle(STD_OUTPUT_HANDLE)
Dim lReturn As Long
Dim lResult As Long
lResult = WriteFile(lHandle, (strOut), Len(strOut), lReturn, ByVal 0&)
If Not lResult Then
MsgBox "HANDLE: " + Str(lHandle) + ", LastDLLError: " +
Str(Err.LastDllError)
End If
End Sub
Public Sub Main()
Out "This is a test"
End Sub
-------------------------------------------------------
Thanks!
--
Grant Schenck
.
- Follow-Ups:
- Prev by Date: Re: Multilined textbox in standard InputBox
- Next by Date: VB6 Command Buttons and GDI's
- Previous by thread: Re: Multilined textbox in standard InputBox
- Next by thread: Re: Why do I get error 6 (The Handle is Invalid) trying to WriteFile to STDOUT from VB 6 exe?
- Index(es):
Relevant Pages
|