Compile an exe in Microsoft Visual C++ 6.0 using the psapi.h
I've been trying to compile an exe in Microsoft Visual C++ 6.0 using the psapi.h library but I keep getting this error;
fatal error C1083: Cannot open include file: 'psapi.h': No such file or directory Error executing cl.exe.
I've looked all over the internet, I found many posts directing me to download and install versions of the Windows SDK. However all those links were dead. If anyone could walk me though configuring 开发者_C百科the Microsoft Visual C++ 6.0 so that it could compile with psapi.h, that would be awesome!
Get the windows or platform sdk directly from microsoft, they shouldn't have any dead links. Failing that, download visual studio 08 or higher and see if it installs the lib & header(I had the exact same problem as you, I solved it by copying the lib and header from the windows sdk that visual studio 2008 comes with).
If psapi.h is not included with the SDK included with VC++ 6.0, then you should probably rather update your compiler that try to use a new SDK with an old tool-chain. PSAPI is supported on versions of Windows released after VC++ 6.0.
Either way the header file alone will not solve your problem; you will also need the appropriate export library and DLL.
The latest versions of the Platform SDK are not compatible with Visual C++ 6.0 - support for that compiler ended years ago. If you didn't get the SDK back when it was available I'm afraid you're out of luck. Microsoft is not bashful about obsoleting things and wiping them out completely.
This works for me:
/*
* Simple utility to call GetProcessMemoryInfo without having
* to compile or link with psapi.h / psapi.lib.
*/
typedef struct {
DWORD cb;
DWORD PageFaultCount;
DWORD PeakWorkingSetSize;
DWORD WorkingSetSize;
DWORD QuotaPeakPagedPoolUsage;
DWORD QuotaPagedPoolUsage;
DWORD QuotaPeakNonPagedPoolUsage;
DWORD QuotaNonPagedPoolUsage;
DWORD PagefileUsage;
DWORD PeakPagefileUsage;
} PROCESS_MEMORY_COUNTERS;
#define Win32MemArgs HANDLE, PROCESS_MEMORY_COUNTERS *, DWORD
extern BOOL WINAPI GetProcessMemoryInfo( Win32MemArgs );
typedef BOOL (WINAPI *GetMemInfo)( Win32MemArgs );
PROCESS_MEMORY_COUNTERS GetMemInfo()
{
PROCESS_MEMORY_COUNTERS pmc;
HANDLE hProc;
char *pf;
BOOL bOK;
static HINSTANCE _hLib = (HINSTANCE)0;
static GetMemInfo _fcn = (GetMemInfo)0;
/*
* Dynamically Load library (once)
*/
if ( !_hLib && (_hLib=::LoadLibrary( "psapi.dll" )) ) {
pf = "GetProcessMemoryInfo";
_fcn = (BOOL (WINAPI *)( Win32MemArgs ))::GetProcAddress( _hLib, pf );
}
/*
* Call fcn
*/
bOK = FALSE
if ( _fcn && (hProc=::GetCurrentProcess()) )
bOK = (*_fcn)( hProc, &pmc, sizeof( pmc ) );
}
if ( !bOK )
memset( &pmc, 0, sizeof( pmc ) );
return pmc;
}
精彩评论