c++ - Visual C++ ShellExecute问题

标签 c++ visual-c++ shellexecute

我正在尝试使用 shellexecute 命令在 Visual C++ 中打开一个文件,我已经包含了以下头文件:

#include "Windows.h"
#include <shellapi.h>
#include <tchar.h>

下面是我在 shellexecute 中使用的内容:

ShellExecute(NULL, _T("Open"), _T("C:\\Program Files\\My Prgram\\test1.pdf"), 
    NULL, NULL, SW_SHOWNORMAL);

但是当我运行它时出现以下错误:

1>test1.obj : error LNK2028: unresolved token (0A000011) "extern "C" struct HINSTANCE__ * __stdcall ShellExecuteW(struct HWND__ *,wchar_t const *,wchar_t const *,wchar_t const *,wchar_t const *,int)" (?ShellExecuteW@@$$J224YGPAUHINSTANCE__@@PAUHWND__@@PB_W111H@Z) referenced in function "private: void __clrcall test1::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@test1@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)

还有另一个几乎相同的错误,即未解析的外部符号而不是未解析的 token 。我到处都在搜索这个,到目前为止有很多错误,但我现在真的被困住了,希望能得到一些帮助。

编辑:请注意,此代码位于按钮单击事件中。

最佳答案

您是否检查了链接器依赖性?尝试查看是否有shell32.lib等。

也可以尝试添加

#pragma comment(lib "shell32.lib")

关于c++ - Visual C++ ShellExecute问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21146977/

相关文章:

c - _aenvptr 和 _wenvptr 的重复定义

c++ - MSVC++ 使用基本运算符 = 重载左值而不是右值?

C++ 使用 ShellExecute 打开链接

c++ - QT 自定义插件 - 提高安全性的方法

c++ - 当我运行这个 shell 脚本时,我收到一个丢失的 ']' 错误

C++11线程与boost线程

linux - Shell 脚本在 Linux 中执行时显示错误

c++ - 如何使用基本类型 uint8_t* 的 std::iterator?

c++ - 在 C++ 中打印时只显示一个字符

visual-c++ - 如何等待 ShellExecute 运行?