如何通过C ++函数获取PC的Mac地址? [英] How to get mac address of pc via c++ function?

查看:102
本文介绍了如何通过C ++函数获取PC的Mac地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void GetMACaddress(void)
{
  unsigned char MACData[6];

  UUID uuid;
  UuidCreateSequential( &uuid );    // Ask OS to create UUID

  for (int i=2; i<8; i++)  // Bytes 2 through 7 inclusive 
                           // are MAC address
    MACData[i - 2] = uuid.Data4[i];

  CString s3=MACData;
.................
}




当我使用上述代码时,出现以下错误
该如何解决?

错误35错误LNK2019:未在函数公共:静态void __cdecl CDemoDlg :: GetMACaddress(void)"中引用的未解析的外部符号__imp__UuidCreateSequential @ 4(?GetMACaddress @ CDemoDlg @@ SAXXZ)DemoDlg.obj MIDIDevDemo v2


错误36致命错误LNK1120:1个未解决的外部设备d:\ chaitra \ Basic版本\ MIDI 22-3-2012专业更新\ Debug \ MIDIDevDemo v2.exe MIDIDevDemo v2


[更新]
解决了错误之后,上述代码中的MACData显示值0X0012aab8,但我的mac(物理地址为6个2位数字,中间用-"分隔,并且与显示的值不同(不带引号).

我可以接受它作为我的Mac ID还是应该更改为更正以得到6个2位数的数字,并用-"分隔,这是实际的Mac地址.

要获取实际的mac地址或物理地址,我的代码应该是什么?




When i use the above code I have the following Error
How to resolve this?

Error 35 error LNK2019: unresolved external symbol __imp__UuidCreateSequential@4 referenced in function "public: static void __cdecl CDemoDlg::GetMACaddress(void)" (?GetMACaddress@CDemoDlg@@SAXXZ) DemoDlg.obj MIDIDevDemo v2


Error 36 fatal error LNK1120: 1 unresolved externals d:\chaitra\Basic version\MIDI 22-3-2012 pro updating\Debug\MIDIDevDemo v2.exe MIDIDevDemo v2


[updated]
After solving The error In above code I have MACData which is showing value 0X0012aab8 but my mac(physical address is 6 2digit numbers separated with"-" and different from the value shown(without quotes).

Can I accept that as my mac Id or what should be changed to correct to get as 6 2digit numbers separated with"-" which is actual mac address.

What should be my code to get actual mac address or physical address?

推荐答案

您必须通过项目设置和标题Rpc.h添加输入库Rpcrt4.lib.到您的项目

请检查此链接获取以下地址的物理(MAC)地址:网络接口卡,并确定它是否是多宿主系统上的主要适配器 [
you have to add the input lib Rpcrt4.lib via project setting and the header Rpc.h to your project

please check this link Getting the Physical (MAC) address of a Network Interface Card and finding out if it is the primary adapter on a multi-homed system[^]


到上面的代码中,我添加了

To The above code I added

char mac_address[18];
sprintf(mac_address,"%02X:%02X:%02X:%02X:%02X:%02X",uuid.Data4[2],uuid.Data4[3],uuid.Data4[4],uuid.Data4[5],uuid.Data4[6],uuid.Data4[7]);




可以替换为-
这给出了6个2位数字的确切mac地址




can replace : with -
This gives the exact mac address of 6 2digits


这篇关于如何通过C ++函数获取PC的Mac地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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