c++怎么调用api函数?

2024年11月27日 18:23
有2个网友回答
网友(1):

#include
#include

using namespace std;

void GetProcessorInfo();
void GetMemInfo();

int main(int argc, char* argv[])
{

GetProcessorInfo();
GetMemInfo();
GetDeviceInfo();

return 0;
}

void GetProcessorInfo()
{
SYSTEM_INFO sysInfo;
string processorType;

GetSystemInfo (&sysInfo);

if (sysInfo.dwProcessorType == PROCESSOR_INTEL_386)
{
processorType = "Intel 386";
}
else if (sysInfo.dwProcessorType == PROCESSOR_INTEL_486)
{
processorType = "Intel 486";
}
else if (sysInfo.dwProcessorType == PROCESSOR_INTEL_PENTIUM)
{
processorType = "Intel Pentium";
}
else if (sysInfo.dwProcessorType == PROCESSOR_MIPS_R4000)
{
processorType = "MIPS";
}
else if (sysInfo.dwProcessorType == PROCESSOR_ALPHA_21064)
{
processorType = "Alpha";
}
else {
processorType = "Unknown";
}

cout << processorType << " " << sysInfo.dwNumberOfProcessors << "核" << endl;
}

void GetMemInfo()
{
MEMORYSTATUS status;

GlobalMemoryStatus(&status);

cout << "内存使用率:" << status.dwMemoryLoad << "%" << endl;
cout << "总物理内存大小:" << status.dwTotalPhys / (1024*1024) << "M" << endl;
cout << "可用物理内存大小:" << status.dwAvailPhys / (1024*1024) << "M" << endl;
}

网友(2):

所谓API就是MFC中的一些函数,按照函数声明直接调用。