Solved

setup problem with the console application

Posted on 2001-08-02
4
188 Views
Last Modified: 2010-05-02
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.


0
Comment
Question by:karanpatel
4 Comments
 
LVL 1

Expert Comment

by:mcbeth
Comment Utility
seems to be a problem with test.bat
I think this file dosn't exists.

0
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
Comment Utility
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
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
 
LVL 5

Expert Comment

by:Netminder
Comment Utility
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now