- Details
- Written by: Stanko Milosev
- Category: Delphi
- Hits: 5810
One note to my self, this is piece of code which I was using for starting application from command prompt and getting an information, was that succesfull or not.
function CaptureConsoleOutput(DosApp : string; var strLog : String): Boolean;
const
ReadBuffer = 1048576;ĂÂ // 1 MB Buffer
var
Security: TSecurityAttributes;
ReadPipe,WritePipe: THandle;
start: TStartUpInfo;
ProcessInfo: TProcessInformation;
Buffer: Pchar;
TotalBytesRead,
BytesRead: DWORD;
Apprunning,n,
BytesLeftThisMessage,
TotalBytesAvail : integer;
xCode: Cardinal;
bolOk: Boolean;
begin
bolOk := False;
with Security do
begin
nlength := SizeOf(TSecurityAttributes);
binherithandle := true;
lpsecuritydescriptor := nil;
end;
if CreatePipe (ReadPipe, WritePipe, @Security, 0) then
begin
// Redirect In- and Output through STARTUPINFO structure
Buffer := AllocMem(ReadBuffer + 1);
FillChar(Start,Sizeof(Start),#0);
start.cb := SizeOf(start);
start.hStdOutput := WritePipe;
start.hStdInput := ReadPipe;
start.dwFlags := STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW;
start.wShowWindow := SW_HIDE;
start.hStdError := WritePipe;
// Create a Console Child Process with redirected input and output
if CreateProcess(nil, PChar(DosApp),
@Security,@Security,
true, CREATE_NO_WINDOW or NORMAL_PRIORITY_CLASS,
nil, nil,
start, ProcessInfo) then
begin
n:=0;
TotalBytesRead:=0;
repeat
// Increase counter to prevent an endless loop if the process is dead
Inc(n,1);
// wait for end of child process
Apprunning := WaitForSingleObject(ProcessInfo.hProcess,100);
Application.ProcessMessages;
// it is important to read from time to time the output information
// so that the pipe is not blocked by an overflow. New information
// can be written from the console app to the pipe only if there is
// enough buffer space.
if not PeekNamedPipe(ReadPipe ,@Buffer[TotalBytesRead],
ReadBuffer, @BytesRead,
@TotalBytesAvail,@BytesLeftThisMessage) then break
else if BytesRead > 0 then
ReadFile(ReadPipe,Buffer[TotalBytesRead],BytesRead,BytesRead,nil);
TotalBytesRead:=TotalBytesRead+BytesRead;
until (Apprunning <> WAIT_TIMEOUT) or (n > 150);
GetExitCodeProcess(ProcessInfo.hProcess,xCode);
if xCode=0 then
bolOk := True
else
bolOk := False;
Buffer[TotalBytesRead]:= #0;
OemToChar(Buffer,Buffer);
strLog := strLog + StrPas(Buffer);
end;
FreeMem(Buffer);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ReadPipe);
CloseHandle(WritePipe);
Result := bolOk;
end;
end;
- Details
- Written by: Stanko Milosev
- Category: Delphi
- Hits: 5180
Ok, here is my little fun application, sendig messages chat and SMS from Delphi using skype.
First, you have to download skype.
Install it, start it, and create / login to your account.
I will not explain every lines of code, instead, you can download source code it from here, or exe file from here.
Most of the code, I copy/pasted from Dr Bob.
Usefull link, where you can find commads you can find it here.
Also, for begging you can download Skype API Tracer.
For example to send me a message over, in tracer enter:
CHAT CREATE stanko.milosev
As a response you should get something like:
> CHAT #stanko.milosev/$someone;f1d9961217eea925 STATUS DIALOG
Now, copyĂÂ #stanko.milosev/$someone;f1d9961217eea925 where someone will be your contact name in skype, and now in tracer put something like:
OPEN CHAT #stanko.milosev/$someone;f1d9961217eea925
And next enter something like:
CHATMESSAGE #stanko.milosev/$someone;f1d9961217eea925 Hello Stanko!
And that is all folks!