UINT CRemoteMacFinderDlg::HexStrToInt(CString hexStr)
{
char *stop;
char  num[3];
UINT res = 0;

//Nothing happens if return 0, just server will not wakeup
if (hexStr.GetLength()>2) {
TRACE(_T("(Length) Invalid Input!"));
return 0; //or perhaps exit;
}

memset(num,'\0',3);

//In Unicode it's: wcscpy
strcpy(num,hexStr);
//In Unicode it's: wcstol
res = strtol(num,&stop,16);

if (res==LONG_MAX || res==LONG_MIN || res==0) {
TRACE(_T("(OverFlow) Invalid Input!"));
return 0; //or perhaps exit;
}
return res;}void CRemoteMacFinderDlg::OnPower() 
{
//User Input
UpdateData(TRUE);
//Socket to send magic packet
CAsyncSocket s;
//Buffer for packet
BYTE magicP[102];

//Validate Input data //Create a string containing all numbers (12 charachter)
CString macAddr = "50784c4b43c0";

//   Fill in magic packet with 102 Bytes of data
//Header
//fill 6 Bytes with 0xFF
for (int i=0;i<6;i++)
magicP[i] = 0xff;

//First 6 bytes (these must be repeated!!)
//fill bytes 6-12
for (i=0;i<6;i++) {
//Get 2 charachters from mac address and convert it to int to fill
//magic packet
magicP[i+6] = HexStrToInt(macAddr.Mid(i*2,2));
}

//fill remaining 90 bytes (15 time repeat)
//Warning : It is higly recommended not to use functions like
//memcpy, read MSDN for more details.
for (i=0;i<15;i++) memcpy(&magicP[(i+2)*6],&magicP[6],6);

//Create a socket to send data
s.Create(atol("10000"),SOCK_DGRAM);
//Customize socket to BROADCAST
BOOL bOptVal = TRUE;
if (s.SetSockOpt(SO_BROADCAST,(char*)&bOptVal,sizeof(BOOL))==SOCKET_ERROR) 
return;

//Broadcast Magic Packet, Hope appropriate NIC will take it ;)
s.SendTo(magicP,102,atol("10000"));

TRACE(_T("Magic packet sent.Remote computer should turn on now."));

//Close the socket and release all buffers
s.Close();
// TODO: Add your control notification handler code here

}
这段代码是从别人的源代码上抄过来的,能在别人的代码中运行,自己新建一个程序,发送了数据包却不能远程唤醒,里面的mac地址和端口号直接写入了数据,请高手看看为什么不能远程唤醒