ShellExecute,WinExec 应用错误

xiake001 2010-11-04 04:03:38
#include<windows.h>
#include <iostream.h>

void main(int argc,char* argv[])
{
cout<<"Opening With WinExec\n";
if (WinExec("D:\Program Files\01.txt",SW_SHOW)<32)
{
MessageBox(NULL,"Can not WinExec",NULL,MB_OK);
}
cout<<"Opening With ShellExecute\n";
if (ShellExecute(NULL,"explore","D:\Program Files\01.txt",NULL,NULL,SW_SHOW)<(HANDLE)32)
{
MessageBox(NULL,"Can not ShellExecute\n",NULL,MB_OK);
}
}
我在D:\Program Files创建了 01.txt,但是ShellExecute,WinExec 都应用 错误,为什么啊?
...全文
117 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
muzizongheng 2010-11-05
  • 打赏
  • 举报
回复
可以在ShellExecute或者WinExec执行后调用GetLastError看看是什么问题。

Error Description
ERROR_FILE_NOT_FOUND The specified file was not found.
ERROR_PATH_NOT_FOUND The specified path was not found.
ERROR_DDE_FAIL The Dynamic Data Exchange (DDE) transaction failed.
ERROR_NO_ASSOCIATION There is no application associated with the given file name extension.
ERROR_ACCESS_DENIED Access to the specified file is denied.
ERROR_DLL_NOT_FOUND One of the library files necessary to run the application can't be found.
ERROR_CANCELLED The function prompted the user for additional information, but the user canceled the request.
ERROR_NOT_ENOUGH_MEMORY There is not enough memory to perform the specified action.
ERROR_SHARING_VIOLATION A sharing violation occurred.
Eleven 2010-11-04
  • 打赏
  • 举报
回复
注意转义字符'\'
zzz_zou 2010-11-04
  • 打赏
  • 举报
回复
\这个转义字符 需要注意
ouyh12345 2010-11-04
  • 打赏
  • 举报
回复
D:\Program Files\01.txt

D:\\Program Files\\01.txt
路径的问题

2,586

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 资源
社区管理员
  • 资源
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧