setup problem with the console application

Hello
I've made an app which reads the reading from a weighing scale.

Everything seems to be working perfect. I made a setup file to deploy it to some other system, the setup is successfully deployed, but when i try opening the app from the menu, it says 'PATH NOT FOUND' and sometimes 'FILE NOT FOUND'. This error is thrown in the very begining of the start of the software. Possibly where i see the error is on the line where i'am allocating the console window to start 'AllocConsole'.

please give me a solution to this at the earliest as i need it on a very urgen basis, i'am pasting source code below.

----------------------------------------------------------Option Explicit

Private Declare Function AllocConsole Lib "kernel32" () As Long
Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
Private Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput As Long, ByVal lpBuffer As String, ByVal nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, lpReserved As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function FreeConsole Lib "kernel32" () As Long

Private Const STD_OUTPUT_HANDLE = -11&

Private hConsole As Long

Private Sub Command1_Click()
Dim app_name As String
Dim txt As String
Dim num_written As Long

    app_name = App.Path
    If Right$(app_name, 1) <> "\" Then app_name = app_name & "\"
    app_name = app_name & "test.bat"

    txt = "Ready to run" & vbCrLf
    WriteConsole hConsole, txt, Len(txt), num_written, vbNullString
    Shell app_name
End Sub
Private Sub Form_Load()
Dim txt As String
Dim num_written As Long

    If AllocConsole() Then
        hConsole = GetStdHandle(STD_OUTPUT_HANDLE)
        If hConsole = 0 Then MsgBox "Couldn't allocate STDOUT"

        ' Present a warning.
        txt = "******************************************" & vbCrLf & _
              "*   Warning: Do not close this window!   *" & vbCrLf & _
              "* Close the VB program's window instead. *" & vbCrLf & _
              "******************************************" & vbCrLf
        WriteConsole hConsole, txt, Len(txt), num_written, vbNullString

        ' Make this form visible and on top.
        Me.Show
        SetFocus
    Else
        MsgBox "Couldn't allocate console"
    End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
    CloseHandle hConsole
    FreeConsole
End Sub
----------------------------------------------------------

Please give me a soln to this at the earliest.


karanpatelAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
TimCotteeConnect With a Mentor Head of Software ServicesCommented:
karanpatel, why are you using a console application for this? It appears that all you are doing is shelling a dos batch file. This can be done in GUI VB just as easily.

Anyway, I can see a couple of potential areas if you continue down this route that may cause problems. One is the existence of test.bat as mcbeth mentions. The other is that if the allocconsole fails, the following section may generate an error:

       hConsole = GetStdHandle(STD_OUTPUT_HANDLE)
       If hConsole = 0 Then MsgBox "Couldn't allocate STDOUT"

       ' Present a warning.
       txt = "******************************************" & vbCrLf & _
             "*   Warning: Do not close this window!   *" & vbCrLf & _
             "* Close the VB program's window instead. *" & vbCrLf & _
             "******************************************" & vbCrLf
       WriteConsole hConsole, txt, Len(txt), num_written, vbNullString

The reason being that though you test for hConsole = 0, the Then clause of this line only displays the message box and then attempts to write to the console anyway. This will cause a file not found or path not found error because the stdout handle is treated as a file handle so the WriteConsole line may be causing this error. The simple fix is to encapsulate this section within the existing If statement as below:
       hConsole = GetStdHandle(STD_OUTPUT_HANDLE)
       If hConsole = 0 Then
          MsgBox "Couldn't allocate STDOUT"
       Else
         ' Present a warning.
         txt = "******************************************" & vbCrLf & _
             "*   Warning: Do not close this window!   *" & vbCrLf & _
             "* Close the VB program's window instead. *" & vbCrLf & _
             "******************************************" & vbCrLf
         WriteConsole hConsole, txt, Len(txt), num_written, vbNullString
       End If
0
 
mcbethCommented:
seems to be a problem with test.bat
I think this file dosn't exists.

0
 
DanRollinsCommented:
Hi karanpatel,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept TimCottee's comment(s) as an answer.

karanpatel, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
NetminderCommented:
Per recommendation, force-accepted.

Netminder
CS Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.