Solved

VB5 EXE for DOS

Posted on 1998-12-29
13
278 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now