在程序里怎么获得局域网内其他计算机的信使服务别名?(50分)

  • 主题发起人 主题发起人 ASDC
  • 开始时间 开始时间
A

ASDC

Unregistered / Unconfirmed
GUEST, unregistred user!
因为有时需要在局域网内发送一些消息,想知道对方是否开启了 messenger服务,所以如果能获得对方的信使服务别名,那他就应该开启了信使服务。
 
呵呵,还望各位英雄指教 ^_^
 
net send 函数
function NetSend(dest, Source, Msg: string): Longint; overload;

type

TNetMessageBufferSendFunction = function(servername, msgname, fromname: PWideChar;

buf: PWideChar; buflen: Cardinal): Longint;

stdcall;

var

NetMessageBufferSend: TNetMessageBufferSendFunction;
SourceWideChar: PWideChar;
DestWideChar: PWideChar;
MessagetextWideChar: PWideChar;
Handle: THandle;

begin

Handle := LoadLibrary('NETAPI32.DLL');
if Handle = 0 then

begin
Result := GetLastError;
Exit;
end;

@NetMessageBufferSend := GetProcAddress(Handle, 'NetMessageBufferSend');

if @NetMessageBufferSend = nil then
begin
Result := GetLastError;
Exit;
end;

MessagetextWideChar := nil;
SourceWideChar := nil;
DestWideChar := nil;

try

GetMem(MessagetextWideChar, Length(Msg) * SizeOf(WideChar) + 1);

GetMem(DestWideChar, 20 * SizeOf(WideChar) + 1);

StringToWideChar(Msg, MessagetextWideChar, Length(Msg) * SizeOf(WideChar) + 1);

StringToWideChar(Dest, DestWideChar, 20 * SizeOf(WideChar) + 1);

if Source = '' then

Result := NetMessageBufferSend(nil, DestWideChar, nil,

MessagetextWideChar, Length(Msg) * SizeOf(WideChar) + 1)

else

begin

GetMem(SourceWideChar, 20 * SizeOf(WideChar) + 1);

StringToWideChar(Source, SourceWideChar, 20 * SizeOf(WideChar) + 1);

Result := NetMessageBufferSend(nil, DestWideChar, SourceWideChar,

MessagetextWideChar, Length(Msg) * SizeOf(WideChar) + 1);

FreeMem(SourceWideChar);

end;

finally

FreeMem(MessagetextWideChar);

FreeLibrary(Handle);

end;

end;

用try发送 返回值
ERROR_ACCESS_DENIED: sMsg := '用户无权限访问该消息.';
ERROR_INVALID_PARAMETER: sMsg := '参数非法.';
ERROR_NOT_SUPPORTED: sMsg := '网络请求不支持.';
NERR_NameNotFound: sMsg := '该计算机没有在网络中找到.';
NERR_NetworkError: sMsg := '发送失败.';
NERR_Success: sMsg := '成功';
 
检测发送是否成功不就行了吗
 
首先谢谢两位的回复。
我目前也是用的检测发送是否成功,但感觉还是差一点功能。
如果能检测到对方没有开启信使服务,就不用给他发了啊,免得发了等半天都收不到返回信号。
 
try this:
http://msdn.microsoft.com/library/en-us/netbios/netbios_3wtd.asp
 
weiwei81123提供的地方看的不太懂,
谢谢各位的参与。以后找到具体答案后再贴出来。
 
后退
顶部