using System;
using System.Runtime.InteropServices;
using System.Net;
using System.Net.Sockets;
namespace TcNetSendPlus
{
public class ClsNetApiSend
{
[DllImport("NetApi32")] public static extern int
NetMessageBufferSend(uint ServerName,uint MsgName, uint FromName,uint Buffer,ulong BufferLen);
private string ThisComputer;
public string lstrError;
public ClsNetApiSend()
{
ThisComputer = Dns.GetHostName();
}
unsafe public static uint GetAddress(string variable)
{
uint ptrptr;
fixed(char* ptr = variable)
{ptrptr = (uint) ptr;}
return ptrptr;
}
public bool Send(string ServerName, string Message )
{
ulong LenMsg;
int Status;
uint ThisPtr, DestPtr, MsgPtr;
string newServerName = "";
try
{
IPHostEntry ipEntry = new IPHostEntry();
LenMsg = (ulong) Message.Length * 2;
ThisPtr = GetAddress(ThisComputer);
MsgPtr = GetAddress(Message);
ipEntry = Dns.Resolve(ServerName);
newServerName = ipEntry.HostName;
DestPtr = GetAddress(newServerName);
}
catch (System.Exception e)
{
this.lstrError = e.Message;
return false;
}
Status = NetMessageBufferSend(ThisPtr,DestPtr,ThisPtr,MsgPtr,LenMsg);
if( Status > 0 )
return false;
else
return true;
}
}
}
http://www.codeproject.com/KB/applications/NetSendPlus.aspx[
^]