NET_API_STATUS nasRc; //return code from NetXxxx()
WCHAR msgname[20];
memset(msgname, 0, 20);
int len = GetDlgItemTextW(this->m_hWnd, IDC_RECEIVER, msgname, 20);
if (len == 0)
{
MessageBox("请输入接受者的电脑名称");
return;
}
//一次NetSend最多发出的字符串为895个字符。
WCHAR buf[1024];
memset(buf, sizeof(WCHAR), 1024);
len = GetDlgItemTextW(this->m_hWnd, IDC_MESSAGE, buf, 1024);
if (len == 0)
{
wcscpy(buf, L":)");
len =2;
}
nasRc=NetMessageBufferSend(NULL, //server name(null means this machine)
msgname, //name(alias) of recipient
NULL, //who this is from
(LPBYTE)buf, //, //message
len*sizeof(WCHAR));
switch(nasRc)
{
case ERROR_ACCESS_DENIED:
m_ctlResult.SetWindowText("ERROR: You do not have access to the requested function.");
break;
case ERROR_INVALID_PARAMETER:
m_ctlResult.SetWindowText("ERROR: One of the passed parameters is invalid.");
break;
case ERROR_NOT_SUPPORTED:
m_ctlResult.SetWindowText("ERROR: This network request is not supported.");
break;
case NERR_NameNotFound:
m_ctlResult.SetWindowText("ERROR: The user name could not be found or is not logged in.");
break;
case NERR_NetworkError:
m_ctlResult.SetWindowText("ERROR: A general failure occurred in the network hardware.");
break;
case NERR_Success:
m_ctlResult.SetWindowText("Message successfully sent!");
break;
default:
m_ctlResult.SetWindowText("ERROR: Unknown error");
break;
}
ERROR_ACCESS_DENIED The user does not have access to the requested information.
ERROR_INVALID_PARAMETER The specified parameter is invalid.
ERROR_NOT_SUPPORTED This network request is not supported.
NERR_NameNotFound The user name could not be found.
NERR_NetworkError A general failure occurred in the network hardware.