Hello,

I'm trying to open a URL wit the default browser in C++ using ShellExecute(), however I'm unable to do this, even using the example into the mocrosoft site.

I'm not sure about what I'm missing.


I have:

#include <windows.h>
...
		private: System::Void Go_home_LinkClicked(System::Object^  sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^  e)
		{
			ShellExecute(NULL, L"open", L"http://www.microsoft.com", NULL, NULL, SW_SHOWNORMAL);
		}

And keep getting the following error:

1>GameTrainer.obj : error LNK2028: unresolved token (0A00001F) "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 GameTrainer::Form1::Go_home_LinkClicked(class System::Object ^,class System::Windows::Forms::LinkLabelLinkClickedEventArgs ^)" (?Go_home_LinkClicked@Form1@GameTrainer@@$$FA$AAMXP$AAVObject@System@@P$AAVLinkLabelLinkClickedEventArgs@Forms@Windows@4@@Z)
1>GameTrainer.obj : error LNK2019: unresolved external symbol "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 GameTrainer::Form1::Go_home_LinkClicked(class System::Object ^,class System::Windows::Forms::LinkLabelLinkClickedEventArgs ^)" (?Go_home_LinkClicked@Form1@GameTrainer@@$$FA$AAMXP$AAVObject@System@@P$AAVLinkLabelLinkClickedEventArgs@Forms@Windows@4@@Z)
1>C:\Users\Otto\Desktop\cheathog\GameTrainer\Debug\GameTrainer.exe : fatal error LNK1120: 2 unresolved externals

Some idea about what I'm doing wrong?...

ShellExecute() is declared in Shellapi.h, not windows.h

I have added that header, but still having the same problem...

What could it be?...

make sure to link with Shell32.lib

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.