我调用了net send实现信使功能,但是我想知道怎样能让我这边得到反馈,即利用netapi32.dll来实现在向我发送回馈消息。告知我目标机已经收到信使消息~或者还有什么除了利用那个dll之外别的方法?
解决方案 »
- DELPHI编程实现MYSQL的基本操作如何实现
- 在TIMAGE上移动,识别鼠标在哪个TIMAGE上???
- 如何实现excel+SQL server的导入与导出
- delphi非法操作
- 关于from3的Button1按钮调用from2的Edit1.text内容问题?/在线结粘.
- 属于哪个控件?
- 请教有关dispatch
- ClearCommError函数在两个不同的单元文件中为什么会返回不同的值,有办法让他们返回相同的值吗
- 没办法,自己解答不出,只好再提一次。谁能帮我?
- ADOQUERY不能在一次提交中(执行adoquery1.ExecSQL语句)执行两个INSERT的SQL语句吗?
- ===delphi 自带的InstallShield不能使用中文,怎样才能可以?===
- 共同讨论:API串口通信问题!
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; function NetSend(Dest, Msg: string): Longint; overload;
begin
Result := NetSend(Dest, '', Msg);
end; function NetSend(Msg: string): Longint; overload;
begin
Result := NetSend('', '', Msg);
end; // Example: procedure TForm1.Button1Click(Sender: TObject);
const
NERR_BASE = 2100;
NERR_NameNotFound = NERR_BASE + 173;
NERR_NetworkError = NERR_BASE + 36;
NERR_Success = 0;
var
Res: Longint;
sMsg: string;
begin
Res := NetSend('LoginName', 'Your Message...');
case Res of
/////也许这里是你要的东西;
ERROR_ACCESS_DENIED: sMsg := 'user does not have access to the requested information.';
ERROR_INVALID_PARAMETER: sMsg := 'The specified parameter is invalid.';
ERROR_NOT_SUPPORTED: sMsg := 'This network request is not supported.';
NERR_NameNotFound: sMsg := 'The user name could not be found.';
NERR_NetworkError: sMsg := 'A general failure occurred in the network hardware.';
NERR_Success: sMsg := 'Message sent!';
end;
ShowMessage(sMsg);
end;
0 The operating system is out of memory or resources.
ERROR_FILE_NOT_FOUND The specified file was not found.
ERROR_PATH_NOT_FOUND The specified path was not found.
ERROR_BAD_FORMAT The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).
SE_ERR_ACCESSDENIED The operating system denied access to the specified file.
SE_ERR_ASSOCINCOMPLETE The filename association is incomplete or invalid.
SE_ERR_DDEBUSY The DDE transaction could not be completed because other DDE transactions were being processed.
SE_ERR_DDEFAIL The DDE transaction failed.
SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out.
SE_ERR_DLLNOTFOUND The specified dynamic-link library was not found.
SE_ERR_FNF The specified file was not found.
SE_ERR_NOASSOC There is no application associated with the given filename extension.
SE_ERR_OOM There was not enough memory to complete the operation.
SE_ERR_PNF The specified path was not found.
SE_ERR_SHARE A sharing violation occurred.
可能就是发不通吧。SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out.
信使服务(messager)调用的函数是NetMessageBufferSend
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. 上面就是它的返回值,如果手边有msdn,里面有更详细的说明
interface
uses SysUtils, Classes;function ToUnicode(str:string;dest:PWideChar):integer;
function SendMsg(Toh,From,Msg:string):integer;
function NetMessageBufferSend(servername:PWideChar;
MsgName:PWideChar;
FromName:PWideChar;
Buf: PWideChar;
var BufLen:integer):integer;cdecl;
implementation
function ToUnicode(str:string;dest:PWideChar):integer;
var
len:integer;
begin
len:=Length(str)*2;
//len:=length(dest^);
StringToWideChar(str,dest,len);
Result:=len;
end;
function NetMessageBufferSend; external 'netapi32.dll' name 'NetMessageBufferSend';function SendMsg(Toh,From,Msg:string):integer;
var
ToName :array [0..64] of WideChar;
WMsgText:array [0..1000] of WideChar;
MsgLen,i:integer;
begin
for i := 0 to 64 do ToName[i] := #0;
ToUnicode(Toh,ToName);
for i := 0 to 1000 do WMsgText[i] := #0; MsgLen:=ToUnicode(Msg,WMsgText);
Result:=NetMessageBufferSend(nil,ToName,nil,@WMsgText,MsgLen);end;end.SendMsg得到返回值。
你判断一下返回值就行了。
可以根据他的返回值来判断,返回0表示成功
别的几样都是失败
具体代码我也有的,要的话可以给我发消息