教程学院
图像设计 多媒体类 机械制图 办公软件 操作系统 系统编程 网站编程 网页制作 数据库类 网络路由 网络工程 网络安全 考试认证
酷网学院
CAD
AutoCad Cam350 ProEngineer GCcam MATLAB Unigraphics SolidWorks CAXA Solid3000 Cimatron EdgeCAM
系统
安全 防火墙 病毒 WinXP Win2003 Vista
数据库
编程
网络
  网站导航: 库库中文网 · 系统编程教程 · VC语言 · VC编程技巧  

求助:下面这段程序变为 C++ 地,要怎么写?谢谢2!

教程推荐
『求助:下面这段程序变为 C++ 地,要怎么写?谢谢2!』如果文章有大量图片,显示会较慢,请等待图片下载完成
 
点击数: 更新时间:2008-9-12 13:21:23 
using System.Management;

public string GetNetCardMacAddress()
      {
            ManagementClass mc;
            ManagementObjectCollection moc;
            mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            moc = mc.GetInstances();
            string str = "";
            foreach (ManagementObject mo in moc)
            {
                if ((bool)mo["IPEnabled"] == true)
                    str = mo["MacAddress"].ToString();

            }
            return str;
    }

这是 C# 的程序
要把它变为 WIN32 下的 C++ 程序,要怎么写?

谢谢!

这个问题第1个回答:
huoqu网卡地址的,网上很多,一艘好多源代码
这个问题第2个回答:
用API  GetAdaptersInfo
这个问题第3个回答:
谢谢 楼上 2 位大哥:
我的系统是没有 NETBIOS 协议
只有 TCP/IP 协议

这个问题第4个回答:
#include "stdio.h"
#include "windows.h"
#include "Iphlpapi.h"
#pragma comment(lib, "Iphlpapi.lib")
void main()
{
int i;
IP_ADAPTER_INFO pAdapterInfo;
ULONG len = sizeof(pAdapterInfo);

if(GetAdaptersInfo(&pAdapterInfo, &len) != ERROR_SUCCESS)
{
printf("GetAdaptersInfo ERROR!\n");
}
else
{
printf("AdapterName: %s\n", pAdapterInfo.Address);
printf("Description: %s\n", pAdapterInfo.Description);
printf("IP Address : %s\n", pAdapterInfo.IpAddressList.IpAddress.String);
printf("IP Mask : %s\n", pAdapterInfo.IpAddressList.IpMask.String);
printf("Gateway IP : %s\n", pAdapterInfo.GatewayList.IpAddress.String);
getchar();
}
}

为什么 pAdapterInfo.Address 打印的是空啊
是不是 %s\n 这里类型不对?

谢谢!
这个问题第5个回答:
printf("MAC: %02x-%02x-%02x-%02x-%02x-%02x\n", pAdapterInfo.Address[0], pAdapterInfo.Address[1],pAdapterInfo.Address[2],pAdapterInfo.Address[3],pAdapterInfo.Address[4],pAdapterInfo.Address[5]);

而且pAdapterInfo是一张单链表,你应该循环读取才对,否则只能获取第一个设备
这个问题第6个回答:
谢谢 greatws  大哥
循环写的话,要怎么写?

这个问题第7个回答:
这是WMI的应用,是用COM实现的,相对于C#和VB来说,用C++实现比较麻烦。
下面是用VC2005实现的:也就是你的代码的C++表述:

#include "stdafx.h"
#define _WIN32_DCOM
#include <iostream>
using namespace std;
#include <comdef.h>
#include <Wbemidl.h>
#include <conio.h>

# pragma comment(lib, "wbemuuid.lib")

BOOL ManageWMI();
int _tmain(int argc, _TCHAR* argv[])
{
    if(!ManageWMI()) printf("%WMI Error!");
    _getch();
    return 0;
}

BOOL ManageWMI()
{
    HRESULT hres;

    // Step 1: --------------------------------------------------
    // Initialize COM. ------------------------------------------

    hres =  CoInitializeEx(0, COINIT_MULTITHREADED);
    if (FAILED(hres))
    {
        cout < < "Failed to initialize COM library. Error code = 0x"
            < < hex < < hres < < endl;
        return 1;                  // Program has failed.
    }

    // Step 2: --------------------------------------------------
    // Set general COM security levels --------------------------
    // Note: If you are using Windows 2000, you need to specify -
    // the default authentication credentials for a user by using
    // a SOLE_AUTHENTICATION_LIST structure in the pAuthList ----
    // parameter of CoInitializeSecurity ------------------------

    hres =  CoInitializeSecurity(
        NULL,
        -1,                          // COM authentication
        NULL,                        // Authentication services
        NULL,                        // Reserved
        RPC_C_AUTHN_LEVEL_DEFAULT,  // Default authentication
        RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation 
        NULL,                        // Authentication info
        EOAC_NONE,                  // Additional capabilities
        NULL                        // Reserved
        );

                     
    if (FAILED(hres))
    {
        cout < < "Failed to initialize security. Error code = 0x"
  &

[1] [2] [3] 下一页

】【关闭窗口
  上一页:
  下一页:
 ·网站导航: 库库中文网 · 系统编程教程 · VC语言 · VC编程技巧
VC编程技巧:相关文章
VC编程技巧点击榜
普通教程关于PDEVICEPROPERTIES地疑难 向
推荐教程Tcp阻塞模式下,发送数据后立即
普通教程扩展函数AcceptEx关于client关闭
普通教程vc程序中直接显示JIF图片
普通教程Python 地数据库操作
普通教程Javascript - Prototype Based 
普通教程QQ魔法表情完成机制
普通教程为你地MFC程序增加宏脚本语言
普通教程发送快捷方式到指定地文件夹
普通教程reference memory ,or when及其
PHOTOSHOP - 基础教程 抠图专题 蒙版专题 3DsMax 基础 设计实例 Maya设计实例
3D设计教程
advertisement
关于站点 - 广告服务 - 联系我们 - 版权隐私 - 免责声明 - 合作伙伴 - 程序支持 - 网站地图 - 返回顶部
网站文本地图
版权所有:库库中文 2005-2007 欢迎各种媒体转载我们的原创作品[转载请注明出处]
copyright ? 2005-2008 www.QQGB.com online services. all rights reserved. 蜀ICP备05015578
Optimized for 1024x768 to Firefox,Opera and MS-IE6. Site powered by EQL. 电脑硬件 电脑知识 教程学习
红盾
热爱电脑,热爱生活
拥有电脑,拥有生命
让我们享受拥有电脑的时光