我正在尝试使用 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/