0

我正在尝试创建一个简单的 C++ 应用程序,它将搜索并列出我的 PC 上的所有 .wav 文件。我试图找出 LNK 1120 错误,但没有运气。谁能指出我正确的方向并告诉我我在这里做错了什么?

#include "stdafx.h"
#include "iostream"
#include "Shlwapi.h"
#include "windows.h"

void FindFilesRecursively(LPCTSTR lpFolder, LPCTSTR lpFilePattern);

int _tmain(int argc, _TCHAR* argv[])
{
    LPCTSTR loc = "C://";
    LPCTSTR ft = ".wav";
    FindFilesRecursively(loc, ft);
    return 0;
}

void FindFilesRecursively(LPCTSTR lpFolder, LPCTSTR lpFilePattern)
{
    TCHAR szFullPattern[MAX_PATH];
    WIN32_FIND_DATA FindFileData;
    HANDLE hFindFile;
    // first we are going to process any subdirectories
    PathCombine(szFullPattern, lpFolder, _T("*"));
    hFindFile = FindFirstFile(szFullPattern, &FindFileData);
    if(hFindFile != INVALID_HANDLE_VALUE)
    {
        do
        {
            if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                // found a subdirectory; recurse into it
                PathCombine(szFullPattern, lpFolder, FindFileData.cFileName);
                FindFilesRecursively(szFullPattern, lpFilePattern);
            }
        } while(FindNextFile(hFindFile, &FindFileData));
        FindClose(hFindFile);
    }
    // now we are going to look for the matching files
    PathCombine(szFullPattern, lpFolder, lpFilePattern);
    hFindFile = FindFirstFile(szFullPattern, &FindFileData);
    if(hFindFile != INVALID_HANDLE_VALUE)
    {
        do
        {
            if(!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
            {
                // found a file; do something with it
                PathCombine(szFullPattern, lpFolder, FindFileData.cFileName);
                std::cout << (_T("%s\n"), szFullPattern);
            }
        } while(FindNextFile(hFindFile, &FindFileData));
        FindClose(hFindFile);
    }
}

这些是我收到的错误消息

1>------ Build started: Project: SearchForFile, Configuration: Debug Win32 ------ 
1>SearchForFile.cpp 
1>SearchForFile.obj : error LNK2019: unresolved external symbol __imp__PathCombineA@12 referenced in function "void __cdecl FindFilesRecursively(char const *,char const *)" (?FindFilesRecursively@@YAXPBD0@Z)
1>c:\users\User\documents\visual studio 2010\Projects\SearchForFile\Debug\SearchForFile.exe : fatal error LNK1120: 1 unresolved externals
> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
4

1 回答 1

2

PathCombine函数在Shlwapi.lib库中,您需要将此库添加到您的项目链接器设置中。

打开您的项目设置并导航到“配置属性->链接器->输入”,然后转到“附加依赖项”选项并在Shlwapi.lib那里添加库。

于 2013-06-22T22:14:04.377 回答