I've inherited a C++ project whose code lives on an XP SP3 virtual machine (yay).
For some reason, even though afxwin.h is included (and I included winbase.h for good measure), when I compile the application, I get a bunch of errors, the root ones are:
error C2065: 'MEMORYSTATUSEX' : undeclared identifier
error C2065: 'GlobalMemoryStatusEx' : undeclared identifier
I found the structure definition on MSDN, so that solved part of my issue (even though this is defined in winbase, it's not coming through for some reason).
typedef struct _MEMORYSTATUSEX {
DWORD dwLength;
DWORD dwMemoryLoad;
DWORDLONG ullTotalPhys;
DWORDLONG ullAvailPhys;
DWORDLONG ullTotalPageFile;
DWORDLONG ullAvailPageFile;
DWORDLONG ullTotalVirtual;
DWORDLONG ullAvailVirtual;
DWORDLONG ullAvailExtendedVirtual;
} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
But that still gives me the issue with GlobalMemoryStatusEx. I tried putting the function definition in the header, which then gave me an unresolved external symbol error.
WINBASEAPI BOOL WINAPI GlobalMemoryStatusEx( LPMEMORYSTATUSEX lpBuffer);
error LNK2001: unresolved external symbol "__declspec(dllimport) int __stdcall GlobalMemoryStatusEx(struct _MEMORYSTATUSEX *)" (__imp_?GlobalMemoryStatusEx@@YGHPAU_MEMORYSTATUSEX@@@Z)
Kernel32.lib is included in the compiler commands, so I'm not sure why this isn't working. I thought maybe the function was deprecated, however I can get this to run just fine in VS2013 on a Windows 7 machine, so it's not that. I think it has something to do with the fact that winbase isn't being recognized, but I haven't worked with C++ for 15 years, so I'm unsure where to start.
Any ideas?
SOLUTION
I doubt many people are interested in the solution, but here it is nonetheless!
I finally found the "Windows Server 2003 SP1 SDK" in the Microsoft download center (a full list of SDKs is available on Wikipedia). I then had to add directories to the Tools->Options within VS6.0, and move them to the top of the list.
And finally, I got to see PROGRAM.exe - 0 error(s)
You should install an SDK that was released after VC 6 and that is new enough to include GlobalMemoryStatusEx
but old enough to work with VC 6.
The SDK that is shipped with VC 6 is too old to include GlobalMemoryStatusEx
.
Or, in my opinion the much better way: upgrade to a newer up-to-date version of Visual Studio (Visual Studio Express Editions can be downloaded for free.).