Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

including exe to c++ program

Status
Not open for further replies.

matematik

Programmer
Aug 13, 2007
8
SI
Can I include an EXE program to my Borland C++ project and than run it from the code?
 
You can distribute the executable with yours and call it by using CreateProcess and it's kind (faq101-1952, faq101-1953, faq101-1954).

James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Ok, now I'm using this function:
void run( LPCTSTR cmd, LPCTSTR dir)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;

memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));

si.dwFlags = STARTF_USESHOWWINDOW ;
si.wShowWindow = SW_SHOW;

TCHAR buffer[ MAX_PATH + 1];
memset( buffer, 0, sizeof( buffer));
_tcscpy( buffer, cmd);

// create the process
BOOL res = CreateProcess( NULL
, buffer
, NULL
, NULL
, FALSE
, CREATE_NEW_PROCESS_GROUP
, NULL
, dir
, &si, &pi);

if ( !res)
{
// handle error
}
WaitForSingleObject( pi.hProcess, INFINITE );
}
but I've got a problem. I cal it like this: run(".\whatever.exe -blabla", ".\").
It works fine, but I don't want to show command prompt window. So how can I hide this window?
 
Try changing si.wShowWindow = SW_SHOW to si.wShowWindow = SW_HIDE. Your options for this are:


VALUE -- Meaning
SW_HIDE Hides the window and activates another window.
SW_MAXIMIZE Maximizes the specified window.
SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the Z order.
SW_RESTORE Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.
SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE Displays the window as a minimized window. The active window remains active.
SW_SHOWNA Displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

so if one doesn't work, try another.


James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top