سؤال

I am trying to use the shellexecute command to open a file in visual c++, I have included the following header files:

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

And the following is what I am using for my 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.

You can also try to add

#pragma comment(lib "shell32.lib")
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top