-2

I'm trying to extract string from resource in the form of indirect string. For the current example I have simply took an indirect string for one of Windows 10 built-in APPS. However, this code returns error in Visual Studio 2015, and I'm not sure why.

I know that unresolved external symbol linker error may be produced when the the definition is missing, but in my case I'm using Microsoft Windows Function and I'm including the right header file, and because of this I'm confused why Visual Studio returns such an error.

I cannot find any useful information on the web for exactly that case.

Here is my example code:

#include "stdafx.h"
#include <Shlwapi.h>


int main()
{
    LPWSTR output = L"";
    LPWSTR input = L"@{Microsoft.BingFinance_4.8.268.0_x86__8wekyb3d8bbwe?ms-resource://Microsoft.BingFinance/Resources/ApplicationTitle}";
    int result = ::SHLoadIndirectString(input, output, sizeof(output), NULL );

    // printf("String result: %s \n", output);

    return 0;
}

And here is the error:

Error LNK2019 unresolved external symbol __imp__SHLoadIndirectString@16 referenced in function _main

Niall
  • 30,036
  • 10
  • 99
  • 142
Mario
  • 87
  • 2
  • 10
  • Thank you for comment, I know that question, but I don't think is a duplicate as in my case I have problems with Windows function, and until now I have not experienced such problems for Windows Functions, and most of the question I guess is about my own implementations. – Mario Apr 11 '16 at 11:41
  • 1
    Answer http://stackoverflow.com/a/12573818/1023911 gives you the answer, see "common causes include". The first cause is the one matching your problem. BTW, when you read the MSDN documentation for any Windows API function you always can read which header file to include and which library to link against. – Werner Henze Apr 11 '16 at 11:46

1 Answers1

3

In addition to including the header (for compile time definition), you need to link in the "Shlwapi.lib" for link time symbol resolution.

The Shlwapi.lib can be added to the "Additional Dependencies" under the linker settings for the project.

In general, the MSDN documentation for the Windows API functions includes a description of the requirements and availability of the function, these include the supported OSes, and the header and library required to be used.

Niall
  • 30,036
  • 10
  • 99
  • 142
  • Thank you for your answer it helped me to solve my problem. But this is not the first time when I use functions from Shlwapi.h, could you please explain me why for this case I need to link the lib file ? – Mario Apr 11 '16 at 11:42
  • The others functions described in that header could be included in a library that you are already linking in (one the pre-populated ones when you created the project). There need not be a one-to-one mapping of header file to library file. The MSDN includes descriptions of the headers and library file needed for each function. – Niall Apr 11 '16 at 11:44