0

I wanted to build a program, which changes the active window, so I did some research and found "HWND". I built a small Program to test it.

void main()
{    
    HWND hWnd = FindWindow(NULL, L"Rechner");
    SetForegroundWindow(hWnd);
}

But,I keep getting the same error.

> Fehler 1 error LNK2028: Nicht aufgel÷stes Token (0A0003AA) ""extern "C" int __stdcall SetForegroundWindow(struct HWND__ *)" (?SetForegroundWindow@@$$J14YGHPAUHWND__@@@Z)", auf das in Funktion ""int __cdecl main(void)" (?main@@$$HYAHXZ)" verwiesen wird.

Tim
  • 8,932
  • 4
  • 43
  • 64
FaNaTic
  • 11
  • 2

2 Answers2

2

add User32.lib to the project.

shivpsin
  • 21
  • 1
0

you are getting a linker error on the symbol SetForegroundWindow defined in Winuser.h which is included by the header window.h.

You included the header because the compiler sees you have the symbol defined (in other case you would get a compiler error) but you did not link with the library where this function is implemented, that is why you are getting a linker error..

To solve this, link with User32 library. You can do this by editing your project linker settings (in Visual Studio go to Project->Properties->Config Properties->Linker->Input->Additional Dependencies) or using a pragma directive, ie:

#pragma comment (lib, "user32") 

The following pragma causes the linker to search for the USER32.LIB library while linking. The linker searches first in the current working directory and then in the path specified in the LIB environment variable.

rmp
  • 1,053
  • 7
  • 15
  • you can't link with a dll, ever! you always have to link with the .lib file. – thang Feb 26 '15 at 09:27
  • well, you can load the .dll manually during runtime using WINAPI functions such as LoadLibrary and GetProcAddress.. but I get your point, thanks, edited my answer now.. – rmp Feb 26 '15 at 09:33