如何使用MinGW调用WMI [英] How to call WMI using MinGW

查看:410
本文介绍了如何使用MinGW调用WMI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在搜索网络(包括MSDN)几天后,为了使用C ++获取硬件唯一ID的方法,我发现我需要使用WMI。实际上,我可以找到一些好的例子,以及像一个。问题是:我不能使用MinGW编译它,但是在Visual Studio使用Microsoft编译器相当好,但与MinGW(我的应用程序编译),它给我几十个错误。
这可能是一个老问题,但不幸的是,我找不到一个解决方案,到目前为止搜索网络的天。我在Windows 7上使用MinGW。

解决方案

MinGW应该允许你访问Win32 api而不需要Visual Studio。 >

以下应该使用MinGW进行编译和运行。

  #include< windows .h> 
#include< stdio.h>

int main()
{
SYSTEM_INFO siSysInfo;

//将硬件信息复制到SYSTEM_INFO结构。

GetSystemInfo(& siSysInfo);

//显示SYSTEM_INFO结构的内容。

printf(硬件信息:\\\
);
printf(OEM ID:%u\\\
,siSysInfo.dwOemId);
printf(处理器数:%u\\\

siSysInfo.dwNumberOfProcessors);
printf(页面大小:%u\\\
,siSysInfo.dwPageSize);
printf(Processor type:%u\\\
,siSysInfo.dwProcessorType);
printf(最低应用程序地址:%lx \\\

siSysInfo.lpMinimumApplicationAddress);
printf(最大应用程序地址:%lx \\\

siSysInfo.lpMaximumApplicationAddress);
printf(Active processor mask:%u\\\

siSysInfo.dwActiveProcessorMask);

return 0;
}

其他阅读帮助您开始使用。


After days of searching the web (Including MSDN) for a way to get Hardware unique IDs using C++, I found that I need to use WMI. Actually I could find some good examples as well like this one. The problem is: I cannot compile it using MinGW however it rund pretty well on Visual Studio using Microsoft compiler, but with MinGW (which my application is compiled with) it gives me dozens of errors. This could sound an old question but unfortunately I couldn't find a solution so far after days of searching the web. I am using MinGW on Windows 7.

解决方案

MinGW should allow you to access the Win32 api's without needing Visual Studio.

The following should compile and run with MinGW.

#include <windows.h>
#include <stdio.h>

int main()
{
   SYSTEM_INFO siSysInfo;

   // Copy the hardware information to the SYSTEM_INFO structure. 

   GetSystemInfo(&siSysInfo); 

   // Display the contents of the SYSTEM_INFO structure. 

   printf("Hardware information: \n");  
   printf("  OEM ID: %u\n", siSysInfo.dwOemId);
   printf("  Number of processors: %u\n", 
      siSysInfo.dwNumberOfProcessors); 
   printf("  Page size: %u\n", siSysInfo.dwPageSize); 
   printf("  Processor type: %u\n", siSysInfo.dwProcessorType); 
   printf("  Minimum application address: %lx\n", 
      siSysInfo.lpMinimumApplicationAddress); 
   printf("  Maximum application address: %lx\n", 
      siSysInfo.lpMaximumApplicationAddress); 
   printf("  Active processor mask: %u\n", 
      siSysInfo.dwActiveProcessorMask); 

   return 0;
}

Additional reading to help you get started.

这篇关于如何使用MinGW调用WMI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆