Link Error: Please help me out
-
Hi, I am getting link error when I complied a program from Microsoft SDK that used PSAPI. I could not figure out whats going on and I tried using unicode and ANSI flags in link settings. No luck. Can someone help me out please? Here is the code #include #include #include void PrintProcessNameAndID( DWORD processID ) { char szProcessName[MAX_PATH] = "unknown"; // Get a handle to the process. HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); // Get the process name. if (NULL != hProcess ) { HMODULE hMod; DWORD cbNeeded; if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ) { GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName) ); } else return; } else return; // Print the process name and identifier. printf( "%s (Process ID: %u)\n", szProcessName, processID ); CloseHandle( hProcess ); } void main( ) { // Get the list of process identifiers. DWORD aProcesses[1024], cbNeeded, cProcesses; unsigned int i; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return; // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); // Print the name and process identifier for each process. for ( i = 0; i < cProcesses; i++ ) PrintProcessNameAndID( aProcesses[i] ); } Link Errors: Linking... ProcessInfo.obj : error LNK2001: unresolved external symbol _GetModuleBaseNameA@16 ProcessInfo.obj : error LNK2001: unresolved external symbol _EnumProcessModules@16 ProcessInfo.obj : error LNK2001: unresolved external symbol _EnumProcesses@12 Debug/ProcessInfo.exe : fatal error LNK1120: 3 unresolved externals Error executing link.exe. ProcessInfo.exe - 4 error(s), 0 warning(s) I am using Windows 2000 Professional SP4 and VC++ 6.0 with SP5. I got this sample from Platform SDK under PSAPI. Please help me out. I am lost. Thanks in Advance, Anil:confused:
-
Hi, I am getting link error when I complied a program from Microsoft SDK that used PSAPI. I could not figure out whats going on and I tried using unicode and ANSI flags in link settings. No luck. Can someone help me out please? Here is the code #include #include #include void PrintProcessNameAndID( DWORD processID ) { char szProcessName[MAX_PATH] = "unknown"; // Get a handle to the process. HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); // Get the process name. if (NULL != hProcess ) { HMODULE hMod; DWORD cbNeeded; if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ) { GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName) ); } else return; } else return; // Print the process name and identifier. printf( "%s (Process ID: %u)\n", szProcessName, processID ); CloseHandle( hProcess ); } void main( ) { // Get the list of process identifiers. DWORD aProcesses[1024], cbNeeded, cProcesses; unsigned int i; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return; // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); // Print the name and process identifier for each process. for ( i = 0; i < cProcesses; i++ ) PrintProcessNameAndID( aProcesses[i] ); } Link Errors: Linking... ProcessInfo.obj : error LNK2001: unresolved external symbol _GetModuleBaseNameA@16 ProcessInfo.obj : error LNK2001: unresolved external symbol _EnumProcessModules@16 ProcessInfo.obj : error LNK2001: unresolved external symbol _EnumProcesses@12 Debug/ProcessInfo.exe : fatal error LNK1120: 3 unresolved externals Error executing link.exe. ProcessInfo.exe - 4 error(s), 0 warning(s) I am using Windows 2000 Professional SP4 and VC++ 6.0 with SP5. I got this sample from Platform SDK under PSAPI. Please help me out. I am lost. Thanks in Advance, Anil:confused:
Are you linking with psapi.lib? Add the following statement to your cpp file.
#pragma comment(lib,"psapi.lib")
John
-
Hi, I am getting link error when I complied a program from Microsoft SDK that used PSAPI. I could not figure out whats going on and I tried using unicode and ANSI flags in link settings. No luck. Can someone help me out please? Here is the code #include #include #include void PrintProcessNameAndID( DWORD processID ) { char szProcessName[MAX_PATH] = "unknown"; // Get a handle to the process. HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); // Get the process name. if (NULL != hProcess ) { HMODULE hMod; DWORD cbNeeded; if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ) { GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName) ); } else return; } else return; // Print the process name and identifier. printf( "%s (Process ID: %u)\n", szProcessName, processID ); CloseHandle( hProcess ); } void main( ) { // Get the list of process identifiers. DWORD aProcesses[1024], cbNeeded, cProcesses; unsigned int i; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return; // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); // Print the name and process identifier for each process. for ( i = 0; i < cProcesses; i++ ) PrintProcessNameAndID( aProcesses[i] ); } Link Errors: Linking... ProcessInfo.obj : error LNK2001: unresolved external symbol _GetModuleBaseNameA@16 ProcessInfo.obj : error LNK2001: unresolved external symbol _EnumProcessModules@16 ProcessInfo.obj : error LNK2001: unresolved external symbol _EnumProcesses@12 Debug/ProcessInfo.exe : fatal error LNK1120: 3 unresolved externals Error executing link.exe. ProcessInfo.exe - 4 error(s), 0 warning(s) I am using Windows 2000 Professional SP4 and VC++ 6.0 with SP5. I got this sample from Platform SDK under PSAPI. Please help me out. I am lost. Thanks in Advance, Anil:confused:
-
Are you linking with psapi.lib? Add the following statement to your cpp file.
#pragma comment(lib,"psapi.lib")
John