2012-06-17 1 views
7

Le code suivant est tiré de here j'ai enlevé toute la partie Windows NT que je travaille sur Windows 7.vs 2010: erreur LNK2028:. Jeton non résolu (0A000342) « extern "C" int __stdcall

Je copiais ce codez et exécutez dans Visual Studio 2010 (Nouveau projet-> VC++ -> CLR-> Console CLR ...) .Mais il donne beaucoup d'erreurs 'c' externes non résolues comme indiqué ci-dessous le code.Quel mal j'ai commis?

#define STRICT 1 

#include <windows.h> 
#include <iostream> 
using namespace std; 

BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) { 
DWORD dwThreadId, dwProcessId; 
HINSTANCE hInstance; 
char String[255]; 
HANDLE hProcess; 
if (!hWnd) 
return TRUE;  // Not a window 
if (!::IsWindowVisible(hWnd)) 
return TRUE;  // Not visible 
if (!SendMessage(hWnd, WM_GETTEXT, sizeof(String), (LPARAM)String)) 
return TRUE;  // No window title 
hInstance = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE); 
dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId); 
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId); 
cout << hWnd << ' ' << dwProcessId << '\t' << String << '\t'; 
cout << "(None)\n"; 
CloseHandle(hProcess); 
return TRUE; 
} 

int main(int argc, char *argv[], char *envp[]) { 
EnumWindows(EnumWindowsProc, NULL); 
return 0; 
} 

génère des erreurs est ce suivantes (et d'autres erreurs semblables non réglées extern C)

1>wndowfind.obj : error LNK2028: unresolved token (0A000342) "extern "C" int __stdcall  
EnumWindows(int (__stdcall*)(struct HWND__ *,long),long)"  3 
([email protected]@[email protected]@[email protected]@Z) referenced in function "int __cdecl 
main(int,char * * const,char * * const)" ([email protected]@[email protected]) 

1>wndowfind.obj : error LNK2028: unresolved token (0A000346) "extern "C" unsigned long 
__stdcall GetWindowThreadProcessId(struct HWND__ *,unsigned long *)"  
([email protected]@[email protected]@[email protected]) referenced in function "int __stdcall 
EnumWindowsProc(struct HWND__ *,long)" ([email protected]@[email protected]@[email protected]) 

1>wndowfind.obj : error LNK2028: unresolved token (0A000347) "extern "C" long __stdcall 
GetWindowLongW(struct HWND__ *,int)" ([email protected]@[email protected]@[email protected]) referenced in 
function "int __stdcall EnumWindowsProc(struct HWND__ *,long)" 
([email protected]@[email protected]@[email protected]) 

1>wndowfind.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall 
EnumWindows(int (__stdcall*)(struct HWND__ *,long),long)" 
([email protected]@[email protected]@[email protected]@Z) referenced in function "int __cdecl 
main(int,char * * const,char * * const)" ([email protected]@[email protected]) 

1>c:\users\afnan\documents\visual studio 2010\Projects\wndowfind\Debug\wndowfind.exe : fatal 
error LNK1120: 10 unresolved externals 
1> 
1>Build FAILED. 

MISE À JOUR

En incluant les bibliothèques (comme suggéré dans les réponses), je suis en mesure d'exécuter avec succès le programme. Mais je ne suis pas en mesure de comprendre pourquoi seulement le premier caractère de la chaîne est l'impression ne au complet, comme on peut le voir dans la sortie:

00010060 2652 S  (None) 
002502B2 5820 C  (None) 
00090402 5160 w  (None) 
00050392 5160 w  (None) 
00060292 3520 F  (None) 
000C02BA 3520 M  (None) 
0001021A 3736 E  (None) 
00040018 896 I  (None) 
00010170 3580 A  (None) 
0002003E 2684 D  (None) 
00030316 4956 N  (None) 
000202DE 3736 D  (None) 
0001031E 2652 S  (None) 
000100EA 2652 P  (None) 

Dans la sortie ci-dessus, S est en fait « commencer », C est " console "etc, j'ai confirmé grâce à l'outil spy ++. Comment puis-je imprimer la chaîne complète au lieu du premier caractère?

+1

Votre projet est probablement configuré pour générer en Unicode, ce qui signifie que vous devez utiliser un tableau wchar_t plutôt qu'un tableau char. –

Répondre

21

Par défaut, les projets CLR n'incluent pas les bibliothèques Windows standard, telles que user32.lib.

Modifiez les propriétés de votre projet, recherchez l'option Entrées de lieur et ajoutez kernel32.lib user32.lib advapi32.lib qui sont les bibliothèques habituelles requises par le code Win32.

+0

A travaillé !!! S'il vous plaît voir ma mise à jour ci-dessus. – gpuguy

+0

C'était insaisissable. Je vous remercie! – twip

Questions connexes