Форум: "Сети";
Текущий архив: 2005.01.23;
Скачать: [xml.tar.bz2];
Внизотправка сообщений по сети Найти похожие ветки
← →
kaon (2004-11-04 15:37) [0]Здаравствуйте, уважаемые мастера! Проблема такая, пытаюсь отправить сообщение на русском языке, а присылается какая-то абракадабра!На английском все нормально! Помогите разобраться
вот код:(взят из интернета)
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;
// MessagetextWideChar: PChar;
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) + 2);
GetMem(DestWideChar, 20 * SizeOf(WideChar) + 2);
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;
{$R *.dfm}
procedure TForm1.btnSendClick(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...");
Res:=NetSend(tTo.Text,tMessage.Text);
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 was successfully sent!";
end;
ShowMessage(sMsg);
end;
← →
-=SS=- © (2004-11-04 15:48) [1]Пользуйся
winExec(Pchar("net send "+kompName+" "+MSG),HW_Hide); И не парься
← →
kaon (2004-11-04 16:03) [2]Спасибо!
Страницы: 1 вся ветка
Форум: "Сети";
Текущий архив: 2005.01.23;
Скачать: [xml.tar.bz2];
Память: 0.45 MB
Время: 0.037 c