为什么ShellExecute不起作用?

Gui*_*Fan -1 c++ shellexecute

#include "ShellAPI.h";
ShellExecute(Handle,NULL,"file.txt",NULL,NULL,SW_RESTORE);
Run Code Online (Sandbox Code Playgroud)

为什么此代码不起作用?

错误画面如下: 忙碌的猫

cdh*_*wie 6

几个问题:

  • 您需要先包含,windows.h然后才能包含shellapi.h
  • 包含系统标头时,应<>在标头周围使用而不是""
  • ;#include指令后不应使用分号。
  • 您的ShellExecute()调用可能需要在一个函数中int main(void)
  • Handle没有定义。您可能需要NULL每个ShellExecute()文档(您应该已经阅读过)。

#include <windows.h>
#include <ShellAPI.h>

int main(void) {
    ShellExecute(NULL, NULL, "file.txt", NULL, NULL, SW_RESTORE);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)