Subject: Re: Get the MACAddress from the computer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Mail sent : 6/22/2005

I have tried with the code, but i get some error like than this :

PIP_ADAPTER_INFO' : undeclared identifier

After that I have added #include Iphlpapi.h with no results
Please, What do you recomend ?

Thanks in advanced,

German
 
Hi German!
I have tried with the code, but i get some error like than this :

PIP_ADAPTER_INFO' : undeclared identifier

After that I have added #include Iphlpapi.h with no results
Please, What do you recomend ?

See: GetAdaptersInfo
http://msdn.microsoft.com/library/en-us/iphlp/iphlp/getadaptersinfo.asp

<quote>
Requires Windows XP, Windows 2000 Professional, Windows Me, or Windows 98
</quote>

See: Using the Windows Headers
http://msdn.microsoft.com/library/en-us/winprog/winprog/using_the_windows_headers.asp

In short: you need to define _WIN32_WINNT and WINVER with the correct
values, befor including the h-file.



See also: How To Get the MAC Address for an Ethernet Adapter
http://support.microsoft.com/default.aspx?scid=kb;en-us;118623

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Hi German!
I have tried with the code, but i get some error like than this :

PIP_ADAPTER_INFO' : undeclared identifier

After that I have added #include Iphlpapi.h with no results
Please, What do you recomend ?

The following code works perfectly with VC7.1:

<code>
#include <winsock2.h>
#include <windows.h>
#include <stdio.h>
#include <Iphlpapi.h>
#pragma comment(lib, "Iphlpapi.lib")
#pragma comment(lib, "wsock32.lib")

void main()
{
ULONG ip;
ULONG buflen;
PIP_ADAPTER_INFO pAdInfo = NULL;
PIP_ADAPTER_INFO pAdInfo_c = NULL;

buflen = 0;
GetAdaptersInfo(pAdInfo, &buflen);
pAdInfo = (struct _IP_ADAPTER_INFO *)new UCHAR[buflen+1];
pAdInfo_c = pAdInfo;
if (GetAdaptersInfo(pAdInfo, &buflen) == ERROR_SUCCESS)
{
do
{
ip = inet_addr(pAdInfo->IpAddressList.IpAddress.String);
if ((ip != 0)&&(ip != 0x7f000001))
{
if (pAdInfo->AddressLength != 0)
{
printf("Adapter-Name: %s\nDescription: %s\nAddress:",
pAdInfo->AdapterName, pAdInfo->Description);
for (int i = 0; i < (int)pAdInfo->AddressLength; i++)
printf(" %02X", pAdInfo->Address);
printf("\n\n");
}
}
pAdInfo = pAdInfo->Next;
} while (pAdInfo != NULL);
}
delete pAdInfo_c;
}
</code>

If you use VC6 or older, you need to update your PSDK
(or declare the structure by your own, but then I think you also need to
dynamically load the address of the funtions; because you do not have
the correct lib-file)

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Hi Jochen :

How is in the case of VC++6.00 ?

German

Jochen Kalmbach said:
Hi German!
I have tried with the code, but i get some error like than this :

PIP_ADAPTER_INFO' : undeclared identifier

After that I have added #include Iphlpapi.h with no results
Please, What do you recomend ?

The following code works perfectly with VC7.1:

<code>
#include <winsock2.h>
#include <windows.h>
#include <stdio.h>
#include <Iphlpapi.h>
#pragma comment(lib, "Iphlpapi.lib")
#pragma comment(lib, "wsock32.lib")

void main()
{
ULONG ip;
ULONG buflen;
PIP_ADAPTER_INFO pAdInfo = NULL;
PIP_ADAPTER_INFO pAdInfo_c = NULL;

buflen = 0;
GetAdaptersInfo(pAdInfo, &buflen);
pAdInfo = (struct _IP_ADAPTER_INFO *)new UCHAR[buflen+1];
pAdInfo_c = pAdInfo;
if (GetAdaptersInfo(pAdInfo, &buflen) == ERROR_SUCCESS)
{
do
{
ip = inet_addr(pAdInfo->IpAddressList.IpAddress.String);
if ((ip != 0)&&(ip != 0x7f000001))
{
if (pAdInfo->AddressLength != 0)
{
printf("Adapter-Name: %s\nDescription: %s\nAddress:",
pAdInfo->AdapterName, pAdInfo->Description);
for (int i = 0; i < (int)pAdInfo->AddressLength; i++)
printf(" %02X", pAdInfo->Address);
printf("\n\n");
}
}
pAdInfo = pAdInfo->Next;
} while (pAdInfo != NULL);
}
delete pAdInfo_c;
}
</code>

If you use VC6 or older, you need to update your PSDK
(or declare the structure by your own, but then I think you also need to
dynamically load the address of the funtions; because you do not have
the correct lib-file)

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
And aditional question:

#include <Iphlpapi.h> only works in VC7.0?
Is possible to download file and then I add it to the proyect in VC6.0?

Thanks again.

German said:
Hi Jochen :

How is in the case of VC++6.00 ?

German

Jochen Kalmbach said:
Hi German!
I have tried with the code, but i get some error like than this :

PIP_ADAPTER_INFO' : undeclared identifier

After that I have added #include Iphlpapi.h with no results
Please, What do you recomend ?

The following code works perfectly with VC7.1:

<code>
#include <winsock2.h>
#include <windows.h>
#include <stdio.h>
#include <Iphlpapi.h>
#pragma comment(lib, "Iphlpapi.lib")
#pragma comment(lib, "wsock32.lib")

void main()
{
ULONG ip;
ULONG buflen;
PIP_ADAPTER_INFO pAdInfo = NULL;
PIP_ADAPTER_INFO pAdInfo_c = NULL;

buflen = 0;
GetAdaptersInfo(pAdInfo, &buflen);
pAdInfo = (struct _IP_ADAPTER_INFO *)new UCHAR[buflen+1];
pAdInfo_c = pAdInfo;
if (GetAdaptersInfo(pAdInfo, &buflen) == ERROR_SUCCESS)
{
do
{
ip = inet_addr(pAdInfo->IpAddressList.IpAddress.String);
if ((ip != 0)&&(ip != 0x7f000001))
{
if (pAdInfo->AddressLength != 0)
{
printf("Adapter-Name: %s\nDescription: %s\nAddress:",
pAdInfo->AdapterName, pAdInfo->Description);
for (int i = 0; i < (int)pAdInfo->AddressLength; i++)
printf(" %02X", pAdInfo->Address);
printf("\n\n");
}
}
pAdInfo = pAdInfo->Next;
} while (pAdInfo != NULL);
}
delete pAdInfo_c;
}
</code>

If you use VC6 or older, you need to update your PSDK
(or declare the structure by your own, but then I think you also need to
dynamically load the address of the funtions; because you do not have
the correct lib-file)

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Ok Nishant, I have reviewed the code and I found that #include Iphlpapi.h
it's a main requirement to implement the proyect; how I did not have it,then
I have downloaded VCToolKitSetup, and after that I just found that file.

I have included it in the same code (lines below) but the new problem is
GetAdaptersInfo' : undeclared identifier

What is the next step?
Thanks in advanced,

German Medina

++++++++++++++++++++++++++++++++++++++++++++++++++++

Nishant Sivakumar said:
See http://www.voidnish.com/articles/ShowArticle.aspx?code=MacIdChanger
(comes with full source code)

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com


German said:
Mail sent : 6/22/2005

I have tried with the code, but i get some error like than this :

PIP_ADAPTER_INFO' : undeclared identifier

After that I have added #include Iphlpapi.h with no results
Please, What do you recomend ?

Thanks in advanced,

German
 
Could you build my sample project? If not, it's possible that your include
directories are not setup properly.

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com


German said:
Ok Nishant, I have reviewed the code and I found that #include Iphlpapi.h
it's a main requirement to implement the proyect; how I did not have
it,then
I have downloaded VCToolKitSetup, and after that I just found that file.

I have included it in the same code (lines below) but the new problem is
GetAdaptersInfo' : undeclared identifier

What is the next step?
Thanks in advanced,

German Medina

++++++++++++++++++++++++++++++++++++++++++++++++++++

Nishant Sivakumar said:
See http://www.voidnish.com/articles/ShowArticle.aspx?code=MacIdChanger
(comes with full source code)

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com


German said:
Mail sent : 6/22/2005

I have tried with the code, but i get some error like than this :

PIP_ADAPTER_INFO' : undeclared identifier

After that I have added #include Iphlpapi.h with no results
Please, What do you recomend ?

Thanks in advanced,

German
 
Nishant :

Would you point me out how can I set up the include directories ?
Because, When I have downloaded VCToolKitSetup, Iphlpapi.h was saved in a
different directory than //Microsoft Visual Studio/VC98/MFC/Incude, I had
copied Iphlpapi.h to //Microsoft Visual Studio/VC98/MFC/Incude.

I guess, here is the problem. What do you think ?

German Medina
+519-662-850
.......................................................................................

Nishant Sivakumar said:
Could you build my sample project? If not, it's possible that your include
directories are not setup properly.

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com


German said:
Ok Nishant, I have reviewed the code and I found that #include Iphlpapi.h
it's a main requirement to implement the proyect; how I did not have
it,then
I have downloaded VCToolKitSetup, and after that I just found that file.

I have included it in the same code (lines below) but the new problem is
GetAdaptersInfo' : undeclared identifier

What is the next step?
Thanks in advanced,

German Medina

++++++++++++++++++++++++++++++++++++++++++++++++++++

Nishant Sivakumar said:
See http://www.voidnish.com/articles/ShowArticle.aspx?code=MacIdChanger
(comes with full source code)

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com


Mail sent : 6/22/2005

I have tried with the code, but i get some error like than this :

PIP_ADAPTER_INFO' : undeclared identifier

After that I have added #include Iphlpapi.h with no results
Please, What do you recomend ?

Thanks in advanced,

German
 
Uhm, copying files from a newer PSDK into an existing one is not a good
idea. You'll end up with a bunch of header files that aren't matched.

You seem to be using VC++ 6. Go to Tools-Options-Directories. You can
set/change the search order there.

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com


German said:
Nishant :

Would you point me out how can I set up the include directories ?
Because, When I have downloaded VCToolKitSetup, Iphlpapi.h was saved in a
different directory than //Microsoft Visual Studio/VC98/MFC/Incude, I had
copied Iphlpapi.h to //Microsoft Visual Studio/VC98/MFC/Incude.

I guess, here is the problem. What do you think ?

German Medina
+519-662-8500
......................................................................................

Nishant Sivakumar said:
Could you build my sample project? If not, it's possible that your
include
directories are not setup properly.

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com


German said:
Ok Nishant, I have reviewed the code and I found that #include
Iphlpapi.h
it's a main requirement to implement the proyect; how I did not have
it,then
I have downloaded VCToolKitSetup, and after that I just found that
file.

I have included it in the same code (lines below) but the new problem
is
GetAdaptersInfo' : undeclared identifier

What is the next step?
Thanks in advanced,

German Medina

++++++++++++++++++++++++++++++++++++++++++++++++++++

:

See
http://www.voidnish.com/articles/ShowArticle.aspx?code=MacIdChanger
(comes with full source code)

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com


Mail sent : 6/22/2005

I have tried with the code, but i get some error like than this :

PIP_ADAPTER_INFO' : undeclared identifier

After that I have added #include Iphlpapi.h with no results
Please, What do you recomend ?

Thanks in advanced,

German
 
Back
Top