Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

setup problem with the console application

Posted on 2001-08-02
4
Medium Priority
?
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Expert Comment

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

0
 
LVL 43

Accepted Solution

by:
TimCottee earned 200 total points
ID: 6344249
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
ID: 7198393
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
ID: 7213216
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

604 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