When I compile the following code in Visual Studio 2019 I receive the following error code: code of the error output. It seems to be a LNK2028 error but I do not understand what is happening. Can someone explain why I receive this error?
Here is my code:
#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);
}
As mentioned in 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.
In this current project it seems like you are missing to include additional dependencies. You can include those by going to Project Properties -> Linker -> Input -> Additional Dependencies. Here you can choose to include the User32.dll
file or choose the "Inherit from parent or project defaults"
option. I believe this will solve your linker errors.