Solved

WinExec

Posted on 1998-03-03
7
1,392 Views
Last Modified: 2013-12-03
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
0
Comment
Question by:youngs101497
[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
  • 5
  • 2
7 Comments
 
LVL 4

Accepted Solution

by:
tflai earned 50 total points
ID: 1411677
It looks to me that your application and the EXE that you want to launch are not in the same directory.
0
 
LVL 4

Expert Comment

by:tflai
ID: 1411678
Use GetModuleFileName(NULL, szCurrentPath, sizeof(szCurrentPath)) to get your application's work directory, then append that with "DRAW".
(That's if you want the application and "DRAW" in the same directory.)
0
 
LVL 4

Expert Comment

by:tflai
ID: 1411679
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);
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:youngs101497
ID: 1411680
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
0
 
LVL 4

Expert Comment

by:tflai
ID: 1411681
How'd about SetCurrentDirectory() to the path that DRAW is in?
0
 

Author Comment

by:youngs101497
ID: 1411682
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
0
 
LVL 4

Expert Comment

by:tflai
ID: 1411683
Launch DRAW with CreateProcess() or ShellExecuteEx(), then wait on it to finish with WaitForSingleObject().
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

724 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