Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C++
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;
.................
}



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?
Posted
Updated 21-Mar-12 19:26pm
v3
Comments
barneyman 22-Mar-12 0:46am    
I'd be more inclined to use GetAdaptersInfo than rely on an undocumented nuance of UUID creation ...

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[^]
 
Share this answer
 
v2
Comments
chaiein 22-Mar-12 1:14am    
Thank you :) It helped to remove the Error:)
chaiein 22-Mar-12 1:24am    
Please check my updated question
Resmi Anna 22-Mar-12 1:37am    
please check the updated answer. This may be helpful I hope
chaiein 22-Mar-12 1:47am    
Thank you Resmi Anna:)
To The above code I added

C++
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]);



can replace : with -
This gives the exact mac address of 6 2digits
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900