|
Find out and tell me, so I know too!
(ducks and runs for cover)
Nah, on a more serious note - did you try with lpOperation holding a pointer to the string "open"?
I've not seen the function used like this before, I've only ever seen it used with open specified.
HOWEVER - I just remembered David's comment about it being memory related earlier and thought to check-out the integer values for the error-codes. Looking into winerror.h we see the following:
#define ERROR_SUCCESS 0L
#define NO_ERROR 0L
#define ERROR_INVALID_FUNCTION 1L
#define ERROR_FILE_NOT_FOUND 2L
#define ERROR_PATH_NOT_FOUND 3L
#define ERROR_TOO_MANY_OPEN_FILES 4L
#define ERROR_ACCESS_DENIED 5L
#define ERROR_INVALID_HANDLE 6L
#define ERROR_ARENA_TRASHED 7L
#define ERROR_NOT_ENOUGH_MEMORY 8L
#define ERROR_INVALID_BLOCK 9L
#define ERROR_BAD_ENVIRONMENT 10L
#define ERROR_BAD_FORMAT 11L
#define ERROR_INVALID_ACCESS 12L
#define ERROR_INVALID_DATA 13L
#define ERROR_OUTOFMEMORY 14L
Which makes me feel foolish for not checking earlier, then going on to ask about the "open" verb. I guess your next bet would be to trawl the net for reports of it failing with an error of 8 (ERROR_NOT_ENOUGH_MEMORY)
Like I said - Interesting problem (but not a fun one)
Best,
Simon
|
|
|
|
|
Try passing a 0 instead of a NULL .
HINSTANCE handle = ShellExecute(0, NULL, strPdfFile, NULL, NULL, SW_SHOW);
|
|
|
|
|
Parameter 1 is an HWND so NULL is the correct value, and is equal to 0 so it would not have any effect. See here[^] for the full specification.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
True, Windows 7 UAC (User Account Control) screws things up.
http://en.wikipedia.org/wiki/User_Account_Control[^] says this about ShellExecute :
ShellExecute(hwnd, "runas", "C:\\Windows\\Notepad.exe", 0, 0, SW_SHOWNORMAL);
In the absence of a specific directive stating what privileges the application requests, UAC will apply heuristics, to determine whether or not the application needs administrator privileges. For example, if UAC detects that the application is a setup program, from clues such as the filename, versioning fields, or the presence of certain sequences of bytes within the executable, in the absence of a manifest it will assume that the application needs administrator privileges.
|
|
|
|
|
Now we have another small project also created in C++, it also launch .CHM file from help menu:
void CMainFrame::LaunchHelp(CString FilePath)
{
SHELLEXECUTEINFO sei;
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = NULL;
sei.hwnd = NULL;
sei.lpVerb = "open";
sei.lpFile = FilePath;
sei.lpParameters= NULL;
sei.nShow = SW_SHOWMAXIMIZED;
sei.hInstApp = NULL;
sei.lpIDList = NULL;
sei.lpClass = NULL;
sei.hkeyClass = NULL;
sei.dwHotKey = NULL;
sei.hIcon = NULL;
sei.hProcess = NULL;
sei.lpDirectory = NULL;
int ReturnCode = ::ShellExecuteEx(&sei);
switch(ReturnCode)
{
case ERROR_FILE_NOT_FOUND:
AfxMessageBox("The specified file was not found.");
break;
case ERROR_PATH_NOT_FOUND:
AfxMessageBox("The specified path was not found.");
break;
case ERROR_ACCESS_DENIED:
AfxMessageBox("Access to the specified file is denied.");
break;
}
}
I works fine in Window 7, I copy this function to my application (also created in C++), but after compile and test it in Window 7, still doesn't work, do we need change some settings to make app work in Window 7?
I compare the settings, the only difference are that
1: in C++ - >Code Generation -> Use run time library: I use Multithreaded DLL, they use Multlhreaded;
2: in General Microsoft Foundation Classes: I use Use MFC in a Shared Library; they use Use MFC in a Static Library.
Thanks!
|
|
|
|
|
The code below works and launches a helpfile in Windws 7.
#include <Windows.h>
#include <tchar.h>
#include <iostream.h>
int main()
{
SHELLEXECUTEINFO sei = {0};
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.lpVerb = _T("open");
sei.lpFile = _T("C:\\windows\\help.CHM");
sei.fMask = SEE_MASK_INVOKEIDLIST;
sei.nShow = SW_SHOWDEFAULT;
DWORD exitCode;
int RetVal = GetExitCodeProcess(sei.hProcess, &exitCode);
cout<<"Errorcode "<<RetVal<<" \n";
if (ShellExecuteEx(&sei) == FALSE)
{
switch(RetVal)
{
case ERROR_FILE_NOT_FOUND:
break;
case ERROR_PATH_NOT_FOUND:
break;
case ERROR_ACCESS_DENIED:
break;
}
return FALSE;
}
return 0;
}
modified 25-Jul-12 13:42pm.
|
|
|
|
|
Now I cannot simply say that ::ShellExecuteEx(&sei) doesn't work in Window 7.
The problem is that it doesn't work in my application created before.
I have a app created using VC++ 6.0 last year, everything is fine except that I cannot open .CHM file from it.
Today I create a new application in MFC in VC++ 6.0, then use the exactly same function as the old application, it can open the .CHM file without any problem.
I check all the project settings for both application, they are same, why same function works in one application, but failed in another application?
|
|
|
|
|
I check the return code by:
int RetVal = GetExitCodeProcess(sei.hProcess, &exitCode);
both XP and window 7 return 0.
|
|
|
|
|
You're calling ShellExecuteEx but testing the return value for the for SE_ERR_ values? With ShellExecuteEx [^], the return value is true/false and the more information is provided by GetLastError() . For backward compatibility, the SE_ERR_ codes are placed in hInst member of the structure.
Try this instead:
SHELLEXECUTEINFO sei = { sizeof(sei) };
sei.fMask = SEE_MASK_NOASYNC
sei.lpFile = FilePath;
sei.nShow = SW_SHOWMAXIMIZED;
if (false == ShellExecuteEx(&sei))
{
}
/* Charles Oppermann */
http://weblogs.asp.net/chuckop
|
|
|
|
|
Yes, you are right, ShellExecuteEx() return true or false.
But still cannot solve my problem.
|
|
|
|
|
Andraw111 wrote:
Yes, you are right, ShellExecuteEx() return true
or false. But still cannot solve my problem. Okay, but what is it returning? True or False?
If false, did you check GetLastError() ? What was it's value?
/* Charles Oppermann */
http://weblogs.asp.net/chuckop
|
|
|
|
|
Thanks for reply, it return 8.
But strange thing is that if I create a brand new MFC project and use the same codes to open .CHM file, it works fine, why?
|
|
|
|
|
I strongly suspect that COM initialization is at issue here[^]. Earlier, I mentioned that COM has to be initialized as follows:
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)
This is why I think you're new project works and the old one doesn't. Is your old project using multithreaded COM? If so, the calls might fail.
[Just saw your other post that resolves your issue. I'm posting this for other people who might encounter ShellExecute problems.]
/* Charles Oppermann */
http://weblogs.asp.net/chuckop
|
|
|
|
|
Ok, I will add them, thanks!
|
|
|
|
|
Finally I found what cause the .CHM file cannot open in Window 7.
In my MFC application, I have a project setting:
Link -> Output ->Reserve field, I put "0x40000000".
I create a testing application, if I don't set "0x40000000" to Reserve field, it works fine, otherwise, it cannot open .CHM file in Window 7.
Even I know the reason, I still cannot solve the problem, since our project is very large, if I remove that setting, when I run my application I get "XX MFC application has encountered a problem and needs to close....".
|
|
|
|
|
Have you initialized COM first? From the remarks section on ShellExecute()[^]:
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)
Can you use ShellExecuteEx[^]? ShellExecuteEx is preferable in this case because you'll get better result information.
Andraw111 wrote: I try to use system() to launch .CHM or PDF file, it works fine in both Window XP and Window 7, but it has MS-DOS black screen there, how can I let MS-DOS not shown? The system() C runtime function would not be appropriate here, as you are a Win32 application.
Try this, from a command prompt, type start myfile.chm and report on what happens. Same for Runas.
/* Charles Oppermann */
http://weblogs.asp.net/chuckop
|
|
|
|
|
Hey guys,
I want to test my firewire card using a C program. I do that for my Ethernet and Serial ports using WIN API's like ReadFile, WriteFile etc. but I was not able to find any such stuff for firewire. Please help me out with this.
Cheers
|
|
|
|
|
Does this[^] help (I see it is a bit dated...)?
Veni, vidi, vici.
|
|
|
|
|
Hi,
I have a picture control on a dialog box in MFC. I'll load an image onto that picture control. I'll draw a line on that image. I want to perform undo/redo functionality in for the drawing. I have done that by saving the bitmaps at each point in LButtonDown, but that thing was not working as when I click on Undo, reload the previous image, I can'n continue drawing the line. If I draw a line, it will not be the same line it will be drawn as a new line.
Can anybody have an idea regarding this.?
Regards,
|
|
|
|
|
Assumed your document has
- a background picture as its file name (drawn first)
- a list of your drawing objects (drawn after)
then an undo operation would meen just the removing of the tail list element and a refreshing
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
If you draw the line in XOR mode, redrawing the same line will erase it.
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|
Hi,
I'm newbie here. I wanted to create a SDI MFC application with 3 views in one window. The layout is like this
=======
+ 1 +
-------------
+ 2 + 3 +
=======
1. List View
2. Tree View
3. Tab control with list view
Can anyone help me on how to design this window at first place. Either using Splitter or Window Explorer option.
Thank you
modified 1-Aug-12 21:30pm.
|
|
|
|
|
It could be a splitter window (2 + 3) in another (1 + (2 + 3))
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
May be the solution is also thinkable for you :
- An MDI app
- The Tabed MDI list-views controlled by the selection in your tree control
- The Tree control is in a pane (CDockablePane) controlled by the selection in your main list control
- The Main list control is in a pane as well
- The layout of the MDI-area and panes is controlled by the Users and remanent for them
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
create three different custom window-class and create those window on the main window when required
|
|
|
|