Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
603 views
in Technique[技术] by (71.8m points)

winapi - ShellExecute Command doesn't work properly in win10

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...