Whenever I try to call EnumDesktopWindows or GetWindowsText the linker vomits out the following:
LocateWindow.obj : error LNK2028: unresolved token (0A00000D) "int __stdcall EnumDesktopWindows(struct HDESK__ *,int (__stdcall*)(struct HWND__ *,long),long)" ( EnumDesktopWindows@@$$J212YGHPAUHDESK__@@P6GHPAUHWND__@@J@ZJ@Z) referenced in function "public: void __thiscall LocateWindow::setPopulateWindowArray(void)" ( setPopulateWindowArray@LocateWindow@@$$FQAEXX
Here is the code: (Yeah, its ugly. I am coming at this slow so I get as much of the concepts down as I can)
// LocateWindow.cpp : main project file.///////////////////////////////////////
#include
"stdafx.h"#include
"LocateWindow.h"//using namespace System;
int
main(array<System::String ^> ^args){
LocateWindow mainLocateWindow;
mainLocateWindow.PopulateWindowArray();
System::Console::WriteLine(L
"Hello World"); return 0;}
//LocateWindow.h///////////////////////////////////////////////////////////////////
#pragma
once#include
<windows.h>using
namespace System::Runtime::InteropServices;
//using namespace System;
static
BOOL WINAPI myEnumWindowsHandler(HWND paramTopLevelHandle, LPARAM paramLPARAM){ int functionTest;LPSTR functionWindowTitle;
functionWindowTitle =
new char[MAX_PATH];functionTest=GetWindowText(paramTopLevelHandle, (LPSTR)functionWindowTitle, MAX_PATH);
if (functionTest){System::Console::WriteLine(functionWindowTitle);
delete functionWindowTitle; return true;}
else{System::Console::WriteLine(
"No Title"); delete functionWindowTitle; return false;}
};
class
LocateWindow{HDESK classDesktop;
public
: void PopulateWindowArray(){::EnumDesktopWindows(NULL, myEnumWindowsHandler, (LPARAM)
this);}
};

calling a WINAPI function from a managed main creates linker error
Scafe
Thanks,
Ayman Shoukry
VC++ Team
Mujeeb_rahman
AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib"
in file corewin_express.vsprops.
The funny thing is I can create a bare bones WIN32 app so it seems my SDK is installed properly :(.
Beaulieu
Thanks,
Ayman Shoukry
VC++ Team
SAS8721
Any ways, I am glad that solved your issue.
Thanks,
Ayman Shoulry
VC++ Team
Michela
Just in case, under the project properties --> linker --> command line, add user32.lib and see if that takes care of the errors.
Thanks,
Ayman Shoukry
VC++ Team
Kajit
LocateWindow.obj : error LNK2028: unresolved token (0A00000D) "int __stdcall EnumDesktopWindows(struct HDESK__ *,int (__stdcall*)(struct HWND__ *,long),long)" ( EnumDesktopWindows@@$$J212YGHPAUHDESK__@@P6GHPAUHWND__@@J@ZJ@Z) referenced in function "public: void __thiscall LocateWindow::PopulateWindowArray(void)" ( PopulateWindowArray@LocateWindow@@$$FQAEXXZ)
LocateWindow.obj : error LNK2028: unresolved token (0A000011) "int __stdcall GetWindowTextA(struct HWND__ *,char *,int)" ( GetWindowTextA@@$$J212YGHPAUHWND__@@PADH@Z) referenced in function "int __stdcall `anonymous namespace'::myEnumWindowsHandler(struct HWND__ *,long)" ( myEnumWindowsHandler@ A0x767a8b47@@$$FYGHPAUHWND__@@J@Z)
LocateWindow.obj : error LNK2019: unresolved external symbol "int __stdcall GetWindowTextA(struct HWND__ *,char *,int)" ( GetWindowTextA@@$$J212YGHPAUHWND__@@PADH@Z) referenced in function "int __stdcall `anonymous namespace'::myEnumWindowsHandler(struct HWND__ *,long)" ( myEnumWindowsHandler@ A0x767a8b47@@$$FYGHPAUHWND__@@J@Z)
LocateWindow.obj : error LNK2019: unresolved external symbol "int __stdcall EnumDesktopWindows(struct HDESK__ *,int (__stdcall*)(struct HWND__ *,long),long)" ( EnumDesktopWindows@@$$J212YGHPAUHDESK__@@P6GHPAUHWND__@@J@ZJ@Z) referenced in function "public: void __thiscall LocateWindow::PopulateWindowArray(void)" ( PopulateWindowArray@LocateWindow@@$$FQAEXXZ)
Arul Ram
Hamish_NZ
If that is the linker command line, you just need to type in user32.lib. I would also macke sure that is not there already. You can confirm this by looking at the build log.
Thanks,
Ayman Shoukry
VC++ Team
RazzleDazzle
DavidNJ
One is a CLR Windows Form. That one compiles and executes great. Until I try to use EnumDesktopWindows, then it goes crazy, complaining during the compile process about me trying to do a _stdcall with the /clr:pure switch.
So I created a second project with a target as a CLR console.
As a CLR console, I can at least create the .obj file, but the linker blows up on it with either link2028 or link2019 errors.
numberonesuperguy
Thanks,
Ayman Shoukry
VC++ Team