youngs101497
asked on
WinExec
What am I doing wrong? I want to run a Windows program from a windows program. When ever I run the following code I get an error 2 (file not found).
#include <windowsx.h>
#include <windows.h>
#include <winbase.h>
#include <stdio.h>
#pragma argsused
/************************* ********** ********** ********** *******/
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WORD wReturn;
char szMsg[80];
wReturn = WinExec("DRAW", SW_SHOWNORMAL );
if (wReturn < 32) {
sprintf(szMsg, "WinExec failed; error code = %d", wReturn);
MessageBox(NULL, szMsg, "Error", MB_ICONSTOP);
}
else {
sprintf(szMsg, "WinExec returned %d", wReturn);
MessageBox(NULL, szMsg, "", MB_OK);
}
This is the example out of the help file, yet I can't get it to do any thing other than return a "file not found" error.
I have also tried LoadModule() with no sucess.
Thanks for your help.
AJY
#include <windowsx.h>
#include <windows.h>
#include <winbase.h>
#include <stdio.h>
#pragma argsused
/*************************
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WORD wReturn;
char szMsg[80];
wReturn = WinExec("DRAW", SW_SHOWNORMAL );
if (wReturn < 32) {
sprintf(szMsg, "WinExec failed; error code = %d", wReturn);
MessageBox(NULL, szMsg, "Error", MB_ICONSTOP);
}
else {
sprintf(szMsg, "WinExec returned %d", wReturn);
MessageBox(NULL, szMsg, "", MB_OK);
}
This is the example out of the help file, yet I can't get it to do any thing other than return a "file not found" error.
I have also tried LoadModule() with no sucess.
Thanks for your help.
AJY
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oops! The "proposed answer" should read:
"It looks to me that your application's current work directory is not the same as the directory that DRAW is in."
Or, if you know where DRAW is always:
WinExec("c:\drawpath\DRAW" , SW_SHOWNORMAL);
"It looks to me that your application's current work directory is not the same as the directory that DRAW is in."
Or, if you know where DRAW is always:
WinExec("c:\drawpath\DRAW"
ASKER
WinExec is described to use a search pattern which in the case of draw, does include thw Windows directory. I have used absolute paths and relitive paths with no success. The problem does not seem to be in the path paramater.
AJY
AJY
How'd about SetCurrentDirectory() to the path that DRAW is in?
ASKER
I found my problem. But when I call the program the two run concurrently. I need the calling program to wait until the called program concludes before the calling program continues. Can I do this with WinExec? If not what can I use.
AJY
AJY
Launch DRAW with CreateProcess() or ShellExecuteEx(), then wait on it to finish with WaitForSingleObject().
(That's if you want the application and "DRAW" in the same directory.)