Getting 'ShellExecute' to work...!?
How do I do it? I want an EXE-file to run from my game. How do I do it?
I''ve tried this:
ShellExecute(NULL, "open", "C:\", NULL, NULL, SW_SHOWNORMAL);
And this:
hinstance ShellExecute(NULL, "open", "C:\", NULL, NULL, SW_SHOWNORMAL);
And this:
hinstance ShellExecute(handle, "open", "C:\", NULL, NULL, SW_SHOWNORMAL);
But it just won''t work. How is it done?
"To some its a six-pack, to me it's a support group."
December 20, 2000 12:43 PM
You can use WinExec(filename, 0)
The 0 tells it not to show.
filename is the exe and any command line. It is a string.
The 0 tells it not to show.
filename is the exe and any command line. It is a string.
I can''t get it to work
Can you tell me more on how to get WinExec to work?
I want to run a application so that it is shown.
Can you tell me more on how to get WinExec to work?
I want to run a application so that it is shown.
"To some its a six-pack, to me it's a support group."
I''m not sure, but for running .exe files, try passing "" as the fourth parameter instead of NULL. The SDK isn''t entirely clear on that point.
As Beer Hunter suggested, the fourth parameter should be some value as in
ShellExecute(NULL, "open", "C:\\MyProggy.exe", "", NULL, SW_SHOWNORMAL);
The Win32SDK.hlp says:
lpParameters (fourth parameter)
If lpFile specifies an executable file, lpParameters is a pointer to a null-terminated string that specifies parameters to be passed to the application.
If lpFile specifies a document file, lpParameters should be NULL.
Micah
ShellExecute(NULL, "open", "C:\\MyProggy.exe", "", NULL, SW_SHOWNORMAL);
The Win32SDK.hlp says:
lpParameters (fourth parameter)
If lpFile specifies an executable file, lpParameters is a pointer to a null-terminated string that specifies parameters to be passed to the application.
If lpFile specifies a document file, lpParameters should be NULL.
Micah
The way I read the docs, and in my own experience, you should be passing that first handle parameter so the last line you tried would be the correct one:
ShellExecute(handle, "open", "C:\", NULL, NULL, SW_SHOWNORMAL);
I don''t know why you put that "hinstance" there though - you''re calling it, not declaring it. That line exactly as written will open the c:\ folder for browsing in Windows Explorer. If you''re trying to run an app you need to substitute the command line for the "C:\" parameter and pass the directory of that app in the fifth parameter (not sure it''s entirely necessary, but that''s what the fifth parameter is supposed to be). So to run notepad (for instance):
ShellExecute(handle, "open", "c:\windows\notepad.exe", NULL, "c:\windows", SW_SHOWNORMAL);
I don''t think you need the full path to the exe in the third param if you pass a directory in the fifth param (assuming it''s the same dir the exe is in), but that''s how I''m doing it in a couple apps and it works.
ShellExecute(handle, "open", "C:\", NULL, NULL, SW_SHOWNORMAL);
I don''t know why you put that "hinstance" there though - you''re calling it, not declaring it. That line exactly as written will open the c:\ folder for browsing in Windows Explorer. If you''re trying to run an app you need to substitute the command line for the "C:\" parameter and pass the directory of that app in the fifth parameter (not sure it''s entirely necessary, but that''s what the fifth parameter is supposed to be). So to run notepad (for instance):
ShellExecute(handle, "open", "c:\windows\notepad.exe", NULL, "c:\windows", SW_SHOWNORMAL);
I don''t think you need the full path to the exe in the third param if you pass a directory in the fifth param (assuming it''s the same dir the exe is in), but that''s how I''m doing it in a couple apps and it works.
In some quick experiments I''ve had no trouble running apps using ShellExecute with a full command line as the 3rd param and NULL for the 4th and 5th.
December 20, 2000 04:25 PM
quote: Original post by MindWipe
I can''t get it to work
Can you tell me more on how to get WinExec to work?
I want to run a application so that it is shown.
This is the function declaration:
UINT WinExec(
LPCSTR lpCmdLine, // command line
UINT uCmdShow // window style
);
WinExec is an old function that should not be used anymore. ShellExecute is another way to do it, but really the right way to do it would be to use CreateProcess. With createprocess you can run the process either blocking or non-blocking which is also nice. Here is an example of using createprocess.
That code will execute the process and wait for it to finish, if you want to let it run async then just remove the waitforsingleobject call.
Hope this helps
Edited by - apoxol on December 20, 2000 6:49:59 PM
STARTUPINFO startup;PROCESSINFO process;memset(&startup, 0, sizeof(startup) );startup.cb = sizeof(startup);if(CreateProcess ( NULL, "c:\myproggie.exe", NULL, NULL, TRUE, 0, NULL, "c:\", &startup, &process )){ WaitForSingleObject ( process.hProcess, INFINITE ); CloseHandle ( process.hProcess );}
That code will execute the process and wait for it to finish, if you want to let it run async then just remove the waitforsingleobject call.
Hope this helps
Edited by - apoxol on December 20, 2000 6:49:59 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement