i have this project in c++ and i want to incorporate it with vb. what i want to happen is that when i click a command button, my .exe file will be opened. I used Shell "C:\........\prog.exe" it did open my .exe but my desired output didn't display. I was using filestreaming in my C++ code that evaluates the values saved in a created input.txt file and displays the result in the dos-based window. What do you guys and gurls suggest i'd do with this?? Oh please help! I've already tried codes i found in a tutorial but still, it didn't work ;(

Dani AI

Generated

Brief diagnostic summary for (and follow-up to ): a VB6 GUI launching a C++ console program can fail to show expected console output for three usual reasons — the console app cannot find its input file (relative path problem), the app exits too fast so the window disappears, or the process is launched with a different working directory/permissions and thus returns an error. Verifying the C++ EXE runs correctly when started from a command prompt is the first step.

Immediate, low-effort fixes and checks:

  • Confirm the C++ program runs from cmd.exe and that it reads the same input.txt the VB menu expects.
  • Use absolute paths for input and output files inside the C++ program or pass the full path as an argument.
  • Make the launched process inherit a working directory that contains input.txt (VB6’s current directory may differ).

Small VB6 patterns that help (replace paths as needed):

Set the VB working folder before launch:

ChDrive "C:"
ChDir "C:\Full\Path\To\ExeFolder"

Launch via cmd.exe so the console stays open (quick diagnostic):

Shell "cmd.exe /k ""C:\Full\Path\prog.exe"""

Use ShellExecute to supply a working directory (keeps relative-file expectations intact):

' Declare ShellExecuteA and call it with lpDirectory = "C:\Full\Path\To\ExeFolder"

For production: either modify the C++ program to accept an input filename or write results to a file that the VB UI reads. Capturing output programmatically (redirecting stdout) requires creating pipes and CreateProcess; see Microsoft’s guide on creating a child process with redirected I/O for a robust implementation: Creating a Child Process with Redirected Input and Output.

Caution: when changing directories use both ChDrive and ChDir on different drives; if an error message appears, copy its exact text — it usually points to the missing file or permission problem.

Recommended Answers

All 2 Replies

I don't understand what you are trying to do? You don't want the C++ app to generate output to the Dos window?

using vb 6, i created a selection menu. it's a selection of all the numerical method programs i made. 4 of which is created using vb while 2 using C++. what i want to happen is that, when i click to select the program i made in C++, it should execute and generate the output to the DOS window. But instead of generating an output, the error message is the one prompted back to me.

I don't understand what you are trying to do? You don't want the C++ app to generate output to the Dos window?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.