I have been trying for 2 hours, ShellExecute gives strange errors, too:
1>learn.obj : error LNK2028: unresolved token (0A00002F) "extern "C" struct HINSTANCE__ * __stdcall ShellExecuteA(struct HWND__ *,char const *,char const *,char const *,char const *,int)" (?ShellExecuteA@@$$J224YGPAUHINSTANCE__@@PAUHWND__@@PBD111H@Z) referenced in function "private: void __clrcall learn::Form1::button1_Click_1(class System::Object ^,class System::EventArgs ^)" (?button1_Click_1@Form1@learn@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>learn.obj : error LNK2019: unresolved external symbol "extern "C" struct HINSTANCE__ * __stdcall ShellExecuteA(struct HWND__ *,char const *,char const *,char const *,char const *,int)" (?ShellExecuteA@@$$J224YGPAUHINSTANCE__@@PAUHWND__@@PBD111H@Z) referenced in function "private: void __clrcall learn::Form1::button1_Click_1(class System::Object ^,class System::EventArgs ^)" (?button1_Click_1@Form1@learn@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
Just a bunch of symbols. It would be helpful if the error was in english.
1 2 3 4
|
LPCSTR a = "cleanup.exe";
ShellExecuteA(NULL, NULL, a, NULL, NULL, 0);
|
I have tried ShellExecuteEX, ShellExecute, ShellExecuteW, ShellExecuteA,
LPCSTR, LPWSTR, TEXT(), L""... all error to the same thing. Unresolved externals.
I cant even get it to work at all, let alone relative paths.
EDIT. Fixed that, I had to link lib32. My program compiles at least, but when I press the button, nothing happens:
ShellExecute(NULL, NULL, L"C:\\Windows\\System32\\cmd.exe", NULL, NULL, 0);
How exactly should I format this to link it to something like CMD? Lets not forget relative paths, too. It's hard to know what the program is getting wrong, because nothing it executing, not even the known programs and locations.