Solved

VB5 EXE for DOS

Posted on 1998-12-29
13
284 Views
Last Modified: 2010-05-03
As antiquated as this may sound there is a reason...  I have an EXE (created in VB5) that accepts command line arguments.  It's run in DOS full-screen.  I DO NOT want any output from this EXE to be put in a window (msgbox, output results on a form text box, etc) I want it to just simply display on the following line of the DOS window.  How would this be done?
0
Comment
Question by:davism
[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
  • 6
  • 3
  • 2
  • +2
13 Comments
 
LVL 1

Expert Comment

by:hddp666
ID: 1453083
You can write the program in QBasic or C (free compilers on the web), and then call the program from VB:

Dim r as long
r = shell("C:\path\program.exe", 1)


0
 
LVL 4

Expert Comment

by:idcanada
ID: 1453084

Sorry lad, it can not be done.
8 years of service.

0
 
LVL 1

Author Comment

by:davism
ID: 1453085
Writing the program in C then calling it from VB is not beneficial.  If I opt to take this route then I would leave VB out of the picture all together and just right it in C.  (There is no benefit of writing the program in C just so that VB can call it.  Unless, of course...I'm missing something.)

As for it NOT being able to be done...I'm not discounting that at all.  It's hard to believe that it can't be done but I also can't rule it out.  
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 2

Expert Comment

by:dm_14
ID: 1453086
Try this ..

IN VB
1. Create an EXE which reads the command line (see  VB help on Command())
< In your project properties set the start up object as >
< Sub Main (). Remove all forms, create a standard      >
< module with your processing routines                  >
2. Perform your processing on the command line
3. Send the message/outputs to a text file

IN A BATCH FILE
4. Create a batch file which the user executes and gives a command line parameter
5. in the batch file send the command line parameter to your EXE
6. Type the contents of the text file generated in 3. to the console screen via the batch file

 a bit involved but does the job.

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1453087
This is the function that you need.
Create a Standard exe and start using sub main.
Now use the following API function in your app.
--WriteConsoleOutput

Don't have a sample at this moment. But maybe it already helps you.
0
 
LVL 1

Author Comment

by:davism
ID: 1453088
Mirkwood, do you know where I can get a sample of this code for VB?  Or if you can provide a sample for VB I'd be willing to increase the points.
0
 
LVL 1

Expert Comment

by:hddp666
ID: 1453089
You're absolutely right about there being little/no point in writing a program in C, and then using VB to call it. If you are only familiar with VB coding, then there is a reason right there to not write the code in C. However, there are QBasic and PowerBasic compilers out there that will produce a DOS executable.

I am going to look into Mirkwood's WriteConsole API answer, as it seems to be the best so far.

Here are the declarations:
Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, lpReserved As Any) As Long

Declare Function WriteConsoleOutput Lib "kernel32" Alias "WriteConsoleOutputA" (ByVal hConsoleOutput As Long, lpBuffer As CHAR_INFO, dwBufferSize As COORD, dwBufferCoord As COORD, lpWriteRegion As SMALL_RECT) As Long

Declare Function WriteConsoleOutputAttribute Lib "kernel32" Alias "WriteConsoleOutputAttribute" (ByVal hConsoleOutput As Long, lpAttribute As Integer, ByVal nLength As Long, dwWriteCoord As COORD, lpNumberOfAttrsWritten As Long) As Long

Declare Function WriteConsoleOutputCharacter Lib "kernel32" Alias "WriteConsoleOutputCharacterA" (ByVal hConsoleOutput As Long, ByVal lpCharacter As String, ByVal nLength As Long, dwWriteCoord As COORD, lpNumberOfCharsWritten As Long) As Long


Here are the types:

Type CHAR_INFO
        Char As Integer
        Attributes As Integer
End Type
Type COORD
        x As Integer
        y As Integer
End Type
Type SMALL_RECT
        Left As Integer
        Top As Integer
        Right As Integer
        Bottom As Integer
End Type



0
 
LVL 1

Author Comment

by:davism
ID: 1453090
Point have increased.  I had already performed the WRITECONSOLE function and it worked.  but considering I had to test this out on NT...The WRITECONSOLE created another DOS WINDOW.  I'm going to test this out the way it is intended...straight DOS application in a non-windows environment.  I'll see how that goes.

Provide an answer instead of a comment and point will be given...assuming this example works  :)   (But it's putting me in the right direction.)
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1453091
To whom are you talking. Maybe you can post the code you have so we can maybe use it as a starting point to help you some more.
0
 
LVL 1

Author Comment

by:davism
ID: 1453092
Sorry, it was directed to either your (Mirkwood) or hddp666.  

(Refer to my last comment about it's current status.

Here is the code that I'm using:

Option Explicit

' Reference to a trasmittal object.
Private mthsendstream As transmittal
Declare Function AllocConsole Lib "kernel32" () As Long
Declare Function FreeConsole Lib "kernel32" () As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) _
        As Long
Declare Function GetStdHandle Lib "kernel32" (ByVal _
        nStdHandle As Long) As Long
Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" _
           (ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal _
           nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, _
           lpReserved As Any) As Long
Public Const STD_OUTPUT_HANDLE = -11&

Private Sub Main()
Dim hConsole As Long
Dim command_line As String
Dim temp_date As String
Dim temp_time As String
Dim temp_db As String * 2
Dim temp_module As String * 20
Dim temp_partner As String * 10
Dim temp_doc As String * 10
Dim temp_doc_type As String * 12
Dim temp_comment As String * 80
Dim send_string As String
Dim X As Integer
Dim type_command As String
Dim Result As Long, sOut As String, cWritten As Long
command_line = Command()
If AllocConsole() Then
    hConsole = GetStdHandle(STD_OUTPUT_HANDLE)
End If
Set mthsendstream = New transmittal
    mthsendstream.get_key
    'Prepare EV log transaction
If command_line = "END" Then
    mthsendstream.data_stream = command_line
Else
    temp_db = "EV"
    temp_date = Format(Date, "yyyy/mm/dd")
    temp_time = Format(Time, "hh:mm:ss")
    send_string = temp_db & command_line & temp_date & temp_time
    mthsendstream.data_stream = send_string
End If
    mthsendstream.send_to_pipe
    sOut = mthsendstream.data_stream & vbCrLf
    Result = WriteConsole(hConsole, ByVal sOut, Len(sOut), cWritten, _ ByVal 0&)
 
End Sub

>>Apologize for the confusion on the my previous response.
0
 
LVL 1

Author Comment

by:davism
ID: 1453093
I've tried various alternatives with no success.  As a result, I have some residual fields defined that are left over from those.  Also, I haven't "cleaned" up the code yet either.
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 150 total points
ID: 1453094
I've not found any method to connect to an existing window. What you can however do is use a small trick using copy and paste.
Copy the sentence to your clipboard. Find the console window (using findwindow). Get the handle to the system menu and call the paste function using sendmessage.
Maybe you can also use sendkeys or something.
0
 
LVL 1

Author Comment

by:davism
ID: 1453095
The whole issue is a little more overhead than what it should be.  So, what I'll end up doing is setting a DOS error switch and let our batch processing product (XLNT) handle the check of the switch.  

However, I will give you the points.

Thanks for all the assistance.
0

Featured Post

Industry Leaders: 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

624 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