How to Fix Microsoft ShellExecuteEx C++ Example?

Daniel Sedory 161 Reputation points
2021-03-31T23:00:50.577+00:00

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

https://learn.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.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,527 questions
0 comments No comments
{count} votes

Accepted answer
  1. David Lowndes 4,711 Reputation points
    2021-03-31T23:07:01.243+00:00

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

    #pragma comment( lib, "Shlwapi" )
    
    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful