简体   繁体   English

Visual C ++ ShellExecute问题

[英]Visual C++ ShellExecute problems

I am trying to use the shellexecute command to open a file in visual c++, I have included the following header files: 我正在尝试使用shellexecute命令在Visual C ++中打开文件,我包括以下头文件:

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

And the following is what I am using for my shellexecute: 以下是我用于shellexecute的内容:

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

However I get the following error when I run this: 但是,运行此命令时出现以下错误:

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)

and also another almost identical error for unresolved external symbol rather than unresolved token. 对于未解析的外部符号而不是未解析的令牌,还有另一个几乎相同的错误。 I have searched everywhere for this and have had many errors up to this point but I am really stuck now and would appreciate some help with this. 我在所有地方都进行了搜索,到现在为止仍然有很多错误,但是我现在真的很困,希望在此方面有所帮助。

EDIT: Please note that this code is placed within a button clicked event. 编辑:请注意,此代码位于按钮单击事件中。

Do you have checked the linker dependecy ? 您是否检查了链接器的依赖性? Try to check if there is shell32.lib and others. 尝试检查是否有shell32.lib等。

You can also try to add 您也可以尝试添加

#pragma comment(lib "shell32.lib")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM