关于网上的读取网卡MAC地址的那段程式
int GetMACAddress()
{
CString strResult=( _T("") );
CString strTemp=( _T("") );
HRESULT hr;
IPAddr ipAddr;
ULONG pulMac[ 2 ];
ULONG ulLen;
char *strInputIP="192.168.0.100 ";
//m_InputIP.GetWindowText( strInputIP );
ipAddr = inet_addr( strInputIP );
memset( pulMac,0xff,sizeof( pulMac ) );
ulLen = 6;
hr = SendARP( ipAddr,0,pulMac,&ulLen );
if( hr == NO_ERROR )
{
strResult.Format( _T("Return %08x,length %8d\r\n"),hr,ulLen );
size_t i, j;
char* szMac = new char[ ulLen * 3 ];
PBYTE pbHexMac = ( PBYTE )pulMac;
//
// Convert the binary MAC address into human-readable
//
for( i = 0,j = 0; i < ulLen - 1; ++i )
{
j += sprintf( szMac+j,"%02X:",pbHexMac[ i ] );
}
sprintf(szMac+j,"%02X",pbHexMac[i]);
strTemp.Format(_T("MAC address %s\r\n"),szMac);
strResult += strTemp;
delete [] szMac;
}
else
{
strResult.Format(_T("Call to SendARP failed.\r\n") );
}
//AfxMessageBox(strResult);
//m_Result.SetWindowText( strResult );
return 0;
}
1.编译时提示:
'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable
deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> D:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdio.h(366) : 参见“sprintf”的声明
1>.(161) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s
instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> D:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdio.h(366) : 参见“sprintf”的声明
2.把sprintf 改为sprintf_sj时提示:“int sprintf_s(char *,size_t,const char *,...)”: 不能将参数 2 从“const char [6]”转换为“size_t”
1> 没有使该转换得以执行的上下文
1>.(161) : error C2664: “int sprintf_s(char *,size_t,const char *,...)”: 不能将参数 2 从“const char [5]
”转换为“size_t”
3.怎样把二进制的MAC地址转换成00-1A-8C-9C-60-38的格式