returning the result of a dos application when finished

hi i use this code to get the result of a dos application but the problem with this is that i cant get all the text back, only the amout that can be cept in a long is returned and i cant seem to make it work as either single or double.

Option Explicit

      Private Declare Function CreatePipe Lib "kernel32" ( _
          phReadPipe As Long, _
          phWritePipe As Long, _
          lpPipeAttributes As Any, _
          ByVal nSize As Long) As Long

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

          nLength As Long
          lpSecurityDescriptor As Long
          bInheritHandle As Long
      End Type

      Private Type STARTUPINFO
         cb As Long
         lpReserved As Long
         lpDesktop As Long
         lpTitle As Long
         dwX As Long
         dwY As Long
         dwXSize As Long
         dwYSize As Long
         dwXCountChars As Long
         dwYCountChars As Long
         dwFillAttribute As Long
         dwFlags As Long
         wShowWindow As Integer
         cbReserved2 As Integer
         lpReserved2 As Long
         hStdInput As Long
         hStdOutput As Long
         hStdError As Long
      End Type

         hProcess As Long
         hThread As Long
         dwProcessID As Long
         dwThreadID As Long
      End Type

      Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
         lpApplicationName As Long, ByVal lpCommandLine As String, _
         lpProcessAttributes As Any, lpThreadAttributes As Any, _
         ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
         ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
         lpStartupInfo As Any, lpProcessInformation As Any) As Long

      Private Declare Function CloseHandle Lib "kernel32" (ByVal _
         hObject As Long) As Long

      Private Const NORMAL_PRIORITY_CLASS = &H20&
      Private Const STARTF_USESTDHANDLES = &H100&

      Private Sub ExecCmd(cmdline$)
          Dim proc As PROCESS_INFORMATION, ret As Long, bSuccess As Long
          Dim start As STARTUPINFO
          Dim sa As SECURITY_ATTRIBUTES, hReadPipe As Long, hWritePipe _
          As Long
          Dim bytesread As Long, mybuff As String
          Dim i As Integer

          mybuff = String(256, Chr$(65))

          sa.nLength = Len(sa)
          sa.bInheritHandle = 1&
          sa.lpSecurityDescriptor = 0&

          ret = CreatePipe(hReadPipe, hWritePipe, sa, 0)
          If ret = 0 Then
              MsgBox "CreatePipe failed. Error: " & Err.LastDllError
              Exit Sub
          End If

       start.cb = Len(start)
       start.dwFlags = STARTF_USESTDHANDLES
       start.hStdOutput = hWritePipe

       ' Start the shelled application:
       ret& = CreateProcessA(0&, cmdline$, sa, sa, 1&, _
       NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
       If ret <> 1 Then
           MsgBox "CreateProcess failed. Error: " & Err.LastDllError
       End If

       bSuccess = ReadFile(hReadPipe, mybuff, 100000, bytesread, 0&)
       If bSuccess = 1 Then
           Text1.Text = Left(mybuff, bytesread)
           MsgBox "ReadFile failed. Error: " & Err.LastDllError
       End If

          ret& = CloseHandle(proc.hProcess)
          ret& = CloseHandle(proc.hThread)
          ret& = CloseHandle(hReadPipe)
          ret& = CloseHandle(hWritePipe)
      End Sub
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tai-SanAuthor Commented:
ups, made a little mistake

ByVal lpBuffer As Long. _
was supposted to be:
ByVal lpBuffer As String
Why don't you send the result to a text file and then have VB read that?

Tai-SanAuthor Commented:
would that do any difference?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Sure, the problem you are having is passing a memory space reference from DOS to VB.  By dealing with a text file you avoid the entire situation all together.  You can start you app in VB do the the shell command to launch your DOS what ever, then when it is done access the text file, get the required info and delete the file. Much cleaner and less code, I bet.

Tai-SanAuthor Commented:
could you give an example?
What is the output of your DOS application?
Tai-SanAuthor Commented:

Mo'PaQ 2000 build 2210 Copyright (c) 2000 Justin Olbrantz(Quantam)
The official client of the MPQ API Library v2.00 by Andrey Lelikov and Quantam
For the most recent version, go to

    Add files: mpq2k a <archive> <*src_file> [int_name] [/c] [/wav] [/r] [/new]
Extract files: mpq2k e <archive> <*int_file> [target_dir] [/fp] [/r]
 Rename files: mpq2k r <archive> <int_file> <new_name>
   Move files: mpq2k m <archive> <*src_file> <target_dir> [/r]
 Delete files: mpq2k d <archive> <*int_file> [/r]
Flush archive: mpq2k f <archive>
   List files: mpq2k l <archive> [filter] [out_file] [/lf] [/p]
  Run scripts: mpq2k s <script>
 Command help: mpq2k h <command>
The link you specified redirects me to 

Tai-SanAuthor Commented:
dont follow the link
the output of the dos program is excactly as said above including the link (though its not a link in dos)
Oh, ok.  Sorry, can you have the DOS program output this to a file?

Tai-SanAuthor Commented:
its not my program, i dont have the source. i am creating a GUI for it but i cant get my code to return enough of the text
I see, does the output normally go the command prompt?

Tai-SanAuthor Commented:
yes it does
Tai-SanAuthor Commented:
could you create an example out of this cause im having many problems with it
Ok, but you will have to wait till tomorrow, since I am on my way home.

Tai-SanAuthor Commented:
Bob LearnedCommented:
BTW are you only getting 256 characters?  You only dimension mybuff to 256 characters.
Tai-SanAuthor Commented:
i solved that one but i found another problem, the program says that it cant get access to listfile.dat

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tai-SanAuthor Commented:
i got it to work this far so that the program works with that code ms provided but im having trouple with the batch file
i use this code in the batch file:

mpq2k.exe > c:\LIST.DAT

but it just wont write more than the first lines, then comes a double new line and it doesnt write any further
Tai-SanAuthor Commented:
i guess ive got what i need to do now:

1: copy my application to a specific path so i can specify all of it
2: make specific batch file
3: delete all, now, unnecesarry files and copy whats been changed

ill return
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.