importing psapi.dll functionality

I have been attempting to use __cdecspl(dllimport) to use psapi functionality with no luck.  According to what documentation I have been able to gather this "should" work.  Any Ideas guys?
#include <afxwin.h>
#include <stdio.h>

typedef struct _MODULEINFO {
    LPVOID lpBaseOfDll;
    DWORD SizeOfImage;
    LPVOID EntryPoint;

    LPVOID FaultingPc;
    LPVOID FaultingVa;

// Structure for GetProcessMemoryInfo()
    DWORD cb;
    DWORD PageFaultCount;
    DWORD PeakWorkingSetSize;
    DWORD WorkingSetSize;
    DWORD QuotaPeakPagedPoolUsage;
    DWORD QuotaPagedPoolUsage;
    DWORD QuotaPeakNonPagedPoolUsage;
    DWORD QuotaNonPagedPoolUsage;
    DWORD PagefileUsage;
    DWORD PeakPagefileUsage;

#ifdef UNICODE
#define GetModuleBaseName  GetModuleBaseNameW
#define GetModuleFileNameEx  GetModuleFileNameExW
#define GetMappedFilenameEx  GetMappedFilenameExW
#define GetDeviceDriverBaseName  GetDeviceDriverBaseNameW
#define GetDeviceDriverFileName  GetDeviceDriverFileNameW
#define GetModuleBaseName  GetModuleBaseNameA
#define GetModuleFileNameEx  GetModuleFileNameExA
#define GetMappedFilenameEx  GetMappedFilenameExA
#define GetDeviceDriverBaseName  GetDeviceDriverBaseNameA
#define GetDeviceDriverFileName  GetDeviceDriverFileNameA
#endif // !UNICODE

__declspec(dllimport) BOOL EnumProcesses(DWORD *lpidProcess, DWORD bb, DWORD *cbNeeded);
__declspec(dllimport) BOOL EnumProcessModules(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded);
__declspec(dllimport) DWORD GetModuleBaseNameA(HANDLE hProcess, HMODULE hModule, LPSTR lpBaseName, DWORD nSize);
__declspec(dllimport) DWORD GetModuleBaseNameW(HANDLE hProcess, HMODULE hModule, LPWSTR lpBaseName, DWORD nSize);
__declspec(dllimport) DWORD GetModuleFileNameExA(HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, DWORD nSize);
__declspec(dllimport) DWORD GetModuleFileNameExW(HANDLE hProcess, HMODULE hModule, LPWSTR lpFilename, DWORD nSize);
__declspec(dllimport) BOOL GetModuleInformation(HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb);
__declspec(dllimport) BOOL EmptyWorkingSet(HANDLE hProcess);
__declspec(dllimport) BOOL QueryWorkingSet(HANDLE hProcess, PVOID pv, DWORD cb);
__declspec(dllimport) BOOL InitializeProcessForWsWatch(HANDLE hProcess);
__declspec(dllimport) BOOL GetWsChanges(HANDLE hProcess, PPSAPI_WS_WATCH_INFORMATION lpWatchInfo, DWORD cb);
__declspec(dllimport) DWORD GetMappedFileNameW(HANDLE hProcess, LPVOID lpv, LPWSTR lpFilename, DWORD nSize);
__declspec(dllimport) DWORD GetMappedFileNameA(HANDLE hProcess, LPVOID lpv, LPSTR lpFilename, DWORD nSize);
__declspec(dllimport) BOOL EnumDeviceDrivers(LPVOID *lpImageBase, DWORD cb, LPDWORD lpcbNeeded);
__declspec(dllimport) DWORD GetDeviceDriverBaseNameA(LPVOID ImageBase, LPSTR lpBaseName, DWORD nSize);
__declspec(dllimport) DWORD GetDeviceDriverBaseNameW(LPVOID ImageBase,LPWSTR lpBaseName,DWORD nSize);
__declspec(dllimport) DWORD GetDeviceDriverFileNameA(LPVOID ImageBase, LPSTR lpFilename, DWORD nSize);
__declspec(dllimport) DWORD GetDeviceDriverFileNameW(LPVOID ImageBase, LPWSTR lpFilename, DWORD nSize);
__declspec(dllimport) BOOL GetProcessMemoryInfo(HANDLE Process, PPROCESS_MEMORY_COUNTERS ppsmemCounters, DWORD cb);

/*void main()
      DWORD aDword[1024], cbNeeded, cProcesses;
      HINSTANCE hInstance=LoadLibrary("psapi");
      CString sProcess="EnumProcesses";
      FARPROC fProc=GetProcAddress(hInstance, sProcess);

void PrintModules( DWORD processID )
    HMODULE hMods[1024];
    HANDLE hProcess;
    DWORD cbNeeded;
    unsigned int i;

    // Print the process identifier.

    printf( "\nProcess ID: %u\n", processID );

    // Get a list of all the modules in this process.

    hProcess = OpenProcess(  PROCESS_QUERY_INFORMATION |
                                    FALSE, processID );

    if( EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
        for ( i = 0; i < (cbNeeded / sizeof(HMODULE)); i++ )
            char szModName[MAX_PATH];

            // Get the full path to the module's file.

            if ( GetModuleFileNameEx( hProcess, hMods[i], szModName,
                // Print the module name and handle value.

                printf("\t%s (0x%08X)\n", szModName, hMods[i] );

    CloseHandle( hProcess );

void main( )
    // Get the list of process identifiers.

    DWORD aProcesses[1024], cbNeeded, cProcesses;
    unsigned int i;

    if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )

    // Calculate how many process identifiers were returned.

    cProcesses = cbNeeded / sizeof(DWORD);

    // Print the name of the modules for each process.

    for ( i = 0; i < cProcesses; i++ )
        PrintModules( aProcesses[i] );
main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) unsigned long __cdecl GetModuleFileNameExA(void *,struct HINSTANCE__ *,char *,unsigned long)" (__imp_?GetModuleFileNameExA@@YAKPAXPAUHINSTANCE__@@PADK@Z)
main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl EnumProcessModules(void *,struct HINSTANCE__ * *,unsigned long,unsigned long *)" (__imp_?EnumProcessModules@@YAHPAXPAPAUHINSTANCE__@@KPAK@Z)
main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl EnumProcesses(unsigned long *,unsigned long,unsigned long *)" (__imp_?EnumProcesses@@YAHPAKK0@Z)
Debug/EnumProcess.exe : fatal error LNK1120: 3 unresolved externals
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I think you need to add psapi.lib to your linker options.  If you're in VC++, open Project Settings and click on the Link tab.  Add psapi.lib to the "Object/library modules" field.  Make sure to do this for all your configurations (using the "Settings For" combo box).

-- Zizzer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
graberAuthor Commented:
Well that was easy points.  I searched for that lib and must have overlooked it.  Just the same zizzer thanks.  I thought I was goint to have to do it with out a lib!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.