Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I m trying to open a file using shellexecute command my code is

ShellExecute(NULL,NULL,itemPath,NULL,NULL,SW_SHOW); 

or

ShellExecute(NULL,L"open",itemPath,NULL,NULL,SW_SHOW); 

I have used both ways but when I m giving path of a folder it opens a folder but when I m giving a full specified path of a file it doesn't work. one thing more if I m giving a hardcode path like for example

ShellExecute(NULL,L"open",L"E:\abc.xlsx",NULL,NULL,SW_SHOW);

than it opens this file. can any one explain why it is happening.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
586 views
Welcome To Ask or Share your Answers For Others

1 Answer

ShellExecute works correctly, and the defect can be found in your code. The only explanation that makes sense is that itemPath is not what you think it is. If it were indeed a pointer to null-terminated character array containing L"E:\abc.xlsx" then ShellExecute would behave as you expect.

You can debug the problem by inspecting the content of itemPath to find out what it really contains. Were you to have provided an MCVE then we could have been more specific in the diagnosis of the problem.

Finally, ShellExecute is deprecated, largely because it provides no good means of reporting failure conditions. You should use ShellExecuteEx instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...