question

DanielSedory-5985 avatar image
0 Votes"
DanielSedory-5985 asked DavidLowndes-6766 commented

How to Fix Microsoft ShellExecuteEx C++ Example?

I've tried the example code in the section "A Simple Example of How to Use ShellExecuteEx" on this page:

https://docs.microsoft.com/en-us/windows/win32/shell/launch?redirectedfrom=MSDN

(as both Console and Windows 32-bit), but keep getting the same errors; AFTER putting the required missing "int" in front of "main()" under Visual Studio Community 2019, 16.9.2 (using "Console" project here, "Debug" "x86" with no changes):

Build started...
1>------ Build started: Project: ShellExample, Configuration: Debug Win32 ------
1>ShellExample.cpp
1>ShellExample.obj : error LNK2019: unresolved external symbol __imp__StrCmpIW@8 referenced in function main
1>ShellExample.obj : error LNK2019: unresolved external symbol
imp_StrRetToBufW@16 referenced in function main
1>ShellExample.obj : error LNK2019: unresolved external symbol
imp_PathFindExtensionW@4 referenced in function _main
1>C:\Users\user\source\repos\ShellExample\Debug\ShellExample.exe : fatal error LNK1120: 3 unresolved externals
1>Done building project "ShellExample.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

As I mentioned above, I tried this beginning with a Windows project using the proper function name there (instead of just int main()) and got the same 3 errors.


Dan, TheStarman.

c++windows-api-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DavidLowndes-6766 avatar image
2 Votes"
DavidLowndes-6766 answered DavidLowndes-6766 commented

You need to link with Shlwapi.lib.
Try adding the following to one of your source files:

 #pragma comment( lib, "Shlwapi" )


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you David,

That did it.

If Microsoft doesn't proof read their examples (e.g., whomever entered the code, missed putting "int" in front of "main()") or update them when necessary, that pretty much defeats their purpose except for those who are experts or have had a lot experience in C++ already.
Someone @ Microsoft should really go over all these examples and rewrite some of the code!


Dan.

0 Votes 0 ·

Hi Dan,

You can use the "is this page helpful" facility on the documentation page to submit your feedback and (hopefully) get it corrected.

0 Votes 0 ·