C++ Windows 应用 LNK2028 错误

C++ WindowsApp LNK2028Error

当我在 Visual Studio 2019 中编译以下代码时,我收到以下错误代码:code of the error output. It seems to be a LNK2028 错误,但我不明白发生了什么。有人可以解释为什么我会收到此错误消息吗?

这是我的代码:

#include "MyForm.h"
#include <windows.h>
#include <windowsx.h>
#include <winuser.h>
#include <tchar.h>
using namespace System;
using namespace System::Windows::Forms;

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    HWND p = FindWindowEx(hwnd, NULL, _T("SHELLDLL_DefView"), false);
    HWND* ret = (HWND*)lParam;
    if (p) {
        // Gets the WorkerW Window after the current one.
        *ret = FindWindowEx(NULL, hwnd, _T("WorkerW"), NULL);
    }
    return true;
}

HWND get_wallpaper_window()
{
    // Fetch the Progman window
    HWND progman = FindWindow(_T("ProgMan"), NULL);
    // Send 0x052C to Progman. This message directs Progman to spawn a
    // WorkerW behind the desktop icons. If it is already there, nothing
    // happens.
    SendMessageTimeout(progman, 0x052C, 0, 0, SMTO_NORMAL, 1000, NULL);
    // We enumerate all Windows, until we find one, that has the SHELLDLL_DefView
    // as a child.
    // If we found that window, we take its next sibling and assign it to workerw.
    HWND wallpaper_hwnd = NULL;
    EnumWindows(EnumWindowsProc, (LPARAM)&wallpaper_hwnd);
    // Return the handle you're looking for.
    return wallpaper_hwnd;
}
[STAThread]


void main(array<String^>^ args)
{
    Application::EnableVisualStyles;
    Application::SetCompatibleTextRenderingDefault(false);
    DEM0::MyForm form;
    Application::Run(% form);
}

this and this post it seems like the issue is due to a linker error which is caused by (I believe 8 function calls) that are depending on libraries implemented by the User32.dll located in C:\windows\system32 more info about this所述。

在当前项目中,您似乎缺少包含其他依赖项的内容。您可以通过转到 Project Properties -> Linker -> Input -> Additional Dependencies 来包含它们。 在这里您可以选择包含 User32.dll 文件或选择 "Inherit from parent or project defaults" 选项。我相信这会解决您的链接器错误。