ShellExecuteEx fails on some file types - Programmer
This is a discussion on ShellExecuteEx fails on some file types - Programmer ; I'm trying to open files from my application. They should be opened
exactly like if they where opened from Explorer. I'm trying to use
ShellExecute/ShellExecuteEx to this.
My code:
SHELLEXECUTEINFO shell;
shell.cbSize = sizeof(shell);
shell.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT;
shell.hInstApp ...
-
ShellExecuteEx fails on some file types
I'm trying to open files from my application. They should be opened
exactly like if they where opened from Explorer. I'm trying to use
ShellExecute/ShellExecuteEx to this.
My code:
SHELLEXECUTEINFO shell;
shell.cbSize = sizeof(shell);
shell.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT;
shell.hInstApp = NULL;
shell.lpVerb = NULL;
shell.lpFile = m_filename;
shell.lpParameters = NULL;
shell.lpDirectory = NULL;
shell.nShow = SW_SHOWNORMAL;
shell.lpIDList = NULL;
shell.lpClass = NULL;
shell.hkeyClass = NULL;
shell.dwHotKey = NULL;
shell.hIcon = NULL;
shell.hProcess = NULL;
BOOL ret = ShellExecuteEx(&shell);
//ShellExecute(NULL, NULL, m_filename, NULL, NULL, SW_SHOWNORMAL);
if( ret == 0)
{
DWORD err = GetLastError();
CString x;
x.Format("%d", err);
MessageBox(x);
}
This code works for most files, but some won't open like cpp- and
h-files. I always gets error code 1155 ("No application is associated
with the specified file for this operation.") when I tries to open an
h-file.
I have changed my associations on cpp-files so they have an default
action (open file with visual c++). But opening cpp-files give me error
code 8 ("Not enough storage is available to process this command.").
Since I can open both h and cpp-files from Explorer I guess there is
something bad with my code. But where? Using ShellExecute instead
doesn't help. If I run the program in Windows XP it open files
correctly. Using verb "open" doesn't work either.
I'm using Visual C++ 6 and Windows 98.
-
Re: ShellExecuteEx fails on some file types
I think that now they recommend using CreateProcess() instead of
ShellExecute/ShellExecuteEx.
--
-------------------------------------------------------------------------
Free software - Baxter Codeworks www.baxcode.com
-------------------------------------------------------------------------
"PEK" wrote in message
news:1120391563.875617.254430@g47g2000cwa.googlegr oups.com...
> I'm trying to open files from my application. They should be opened
> exactly like if they where opened from Explorer. I'm trying to use
> ShellExecute/ShellExecuteEx to this.
>
> My code:
>
> SHELLEXECUTEINFO shell;
>
> shell.cbSize = sizeof(shell);
> shell.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT;
> shell.hInstApp = NULL;
> shell.lpVerb = NULL;
> shell.lpFile = m_filename;
> shell.lpParameters = NULL;
> shell.lpDirectory = NULL;
> shell.nShow = SW_SHOWNORMAL;
> shell.lpIDList = NULL;
> shell.lpClass = NULL;
> shell.hkeyClass = NULL;
> shell.dwHotKey = NULL;
> shell.hIcon = NULL;
> shell.hProcess = NULL;
>
> BOOL ret = ShellExecuteEx(&shell);
> //ShellExecute(NULL, NULL, m_filename, NULL, NULL, SW_SHOWNORMAL);
>
> if( ret == 0)
> {
> DWORD err = GetLastError();
> CString x;
> x.Format("%d", err);
> MessageBox(x);
> }
>
> This code works for most files, but some won't open like cpp- and
> h-files. I always gets error code 1155 ("No application is associated
> with the specified file for this operation.") when I tries to open an
> h-file.
>
> I have changed my associations on cpp-files so they have an default
> action (open file with visual c++). But opening cpp-files give me error
> code 8 ("Not enough storage is available to process this command.").
>
> Since I can open both h and cpp-files from Explorer I guess there is
> something bad with my code. But where? Using ShellExecute instead
> doesn't help. If I run the program in Windows XP it open files
> correctly. Using verb "open" doesn't work either.
>
> I'm using Visual C++ 6 and Windows 98.
>
-
Re: ShellExecuteEx fails on some file types
"PEK" wrote in message
news:1120391563.875617.254430@g47g2000cwa.googlegr oups.com...
> I'm trying to open files from my application. They should be opened
> exactly like if they where opened from Explorer. I'm trying to use
> ShellExecute/ShellExecuteEx to this.
>
Does the following code work for you?
// Setup to launch:
SHELLEXECUTEINFO execInfo;
memset (&execInfo, 0, sizeof(SHELLEXECUTEINFO));
execInfo.cbSize = sizeof(SHELLEXECUTEINFO);
execInfo.lpFile = m_filename;
execInfo.nShow = SW_SHOWNORMAL;
execInfo.lpVerb = _T("open");
execInfo.hwnd = m_hWnd; // parent window for error messages
// Launch app; abort if failure
if ( !ShellExecuteEx (&execInfo) ) // failed
return (int) execInfo.hInstApp; // return error code
In particular, maybe your flag of SEE_MASK_FLAG_DDEWAIT is screwing it up.
-- David
http://www.dcsoft.com