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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple calls to ShellExecute IN Shell32.dll 1

Status
Not open for further replies.

dbMark

Programmer
Apr 10, 2003
1,515
US
I already know in a limited way how to use ShellExecute and the API call to Shell32.dll to open another program. Since I have dozens of VFP programs compiled as separate EXEs, the desktops are getting cluttered. Besides, I need to manage all the user rights so the users never even sees programs he doesn't have rights to open. It would be great to manage that with a central core VFP application that acts as a huge menu for the users and the users would only see the programs they have rights to based on one user-access table used in the app. That way it would be simple to manage from a central database. My questions are:

1. Can I have my VFP project make multiple calls to multiple programs on the "menu" or selection list? Can I have several open at once, not just one at a time?

2. Can my original menu program be closed and the called programs keep working? (I know the call to the API is designed so that when the called program terminates, it returns a value to the caller program with the results as a numeric value.)

I looked over some other posts such as thread184-787490 and seen informative links such as

Code:
DECLARE INTEGER ShellExecute IN Shell32.DLL ;
	INTEGER nWinHandle,;
	STRING cOperation,;
	STRING cFileName,;
	STRING cParameters,;
	STRING cDirectory,;
	INTEGER nShowWindow

nResults = ShellExecute(0,"open","VFP_APP.EXE","'"+cInvoiceNo+"' '"+cData+"'","C:\MyApps",1)

As a side point, what confuses me too is I looked in the VFP 9.0 help and it described a ShellExecute foundation class that only allowed 3 parameters. Is this something totally unrelated to the ShellExecute I've been using above?

Found in VFP 9.0 Help:
Syntax: ShellExecute(tcFileName, tcWorkDir, tcOperation)
Return: nSuccess

Thanks for your help, as always,
dbMark
 
INCORRECT: (I know the call to the API is designed so that when the called program terminates, it returns a value to the caller program with the results as a numeric value.)
Sorry, I should have said:

(I know the call to the API is designed so that when the called program begins, it returns a value to the caller program with the results of the request as a numeric value. If that result is 32 or below then there was an error, but if over 32 then the integer is the handle of the main window of the application which has been launched and could be useful if you want to use other API functions to manipulate the window in some way.)
 
dbMark,

Not sure if this answers your questions, but I'll try.

First, you don't need to use ShellExecute() to launch another VFP executable. You can just DO the EXE. The big difference is that ShellExecute() is asynchronous. Once you have launched the new executable, the original program is still running and the user can interact with it. That's not necessarily the case with DO.

With ShellExecute(), there's nothing stopping the user launching one program, then immediately going back to the launching program and running another. Is that what you mean by "make multiple calls"?

If you do use ShellExecute(), the user will indeed be able to close the calling program without affecting the called program.

Next ... the ShellExecute foundation class is merely a wrapper for the ShellExecute() API call. If you know how to use the API -- and it's obvious from your post that you do -- ignore the foundation class.

You are right that ShellExecute() returns its value as soon as it is called. It does not notify the caller that it has terminated.

Finally, I'm glad you found my article useful. Perhaps you could note that the URL is slightly out of date. I am in the process of re-organising my site, and the URL in question has changed to (almost the same -- just get rid of the demon).

Hope this helps.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike, you answered my questions perfectly. Thanks!

Just curious, if I wished, could I declare just any text phrase to the API? Could I use ShellExec or RunMyExe rather than ShellExecute? I'm guessing I could name it almost anything I wished.
 
dbMark,

Glad my answer was helpful, but I'm puzzled by your follow-up question. What do you mean by "declare just any text phrase to the API?".

Are you asking if you can assign an alias to an API call? In other words, you don't like the name ShellExecute, and you'd rather refer to it as, say, RunDBMarkProgam.

Yes, you can do that:

DECLARE INTEGER ShellExecute IN Shell32.DLL ;
AS RunDBMarkProgam ;
INTEGER nWinHandle,;
STRING cOperation,;
STRING cFileName,;
STRING cParameters,;
STRING cDirectory,;
INTEGER nShowWindow

nResults = RunDBMarkProgam ;
(0,"open","VFP_APP.EXE","'"+cInvoiceNo+"' '"+cData+"'","C:\MyApps",1)

Is that what you had in mind?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks, Mike, you answered my question. I wasn't sure if "ShellExecute" was a required name or if just any name picked out of the air would do. You verified tht I could alias it as anything but that specific name is required in the declaration.
 

dbMark,

Yes, that's completely correct. But that also applies to all API calls. In general, the base name is fixed, but you can alias it to anything you like.

That's a useful thing to do if the API name clashes with the name of a VFP function.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top