Hi!
On 18.07.2010 19:52, Bernd wrote:
2010/7/18 Sven Barth<[email protected]>:
Hi again!
I took the time to implement a OutputToDebugMonitor myself. It prints the
message directly to e.g. DebugView even if a debugger like GDB is attached
to the process.
Wow! That was fast! I didn't even consider implementing this myself
after looking at the code for a while.
I was bored...
And afterall it was a pretty simple conversion from C to Pascal... not
much thinking involved ^^
(* first try to open the mutex, if that fails call OutputDebugString, which
will create that for us (we can't do that ourselves easily) *)
mutex := OpenMutexW(SYNCHRONIZE or READ_CONTROL or MUTANT_QUERY_STATE, True,
PWideChar(DBWinMutex));
if mutex = 0 then begin
OutputDebugStringA(PChar(aStr));
Exit;
end;
Does this really create the mutex or wouldn't the original
OutputDebugString() just raise the debug exception and invoke the
debugger and then return before it even comes to the point where the
mutex is needed?
Good point... in that case there are only two things we can do:
1) Rely on the fact that OutputDebugString got at least called once
since the system started while no debugger was attached.
2) Create the mutex by ourselves if we can't open it.
I personally would chose 1, because for 2 I don't know whether all
Windows versions create the Mutex with the same security attributes as
ReactOS does.
To ensure that OutputDebugString was "successfully" called at least once
we could write a really simple (maybe even C) application that calls
OutputDebugString and which is started from our process (thus no
debugger attached). This is done if OpenMutexW fails. After that we try
to open the mutex again and if that fails as well we'll have to give up
(or simply call OutputDebugString to get the message anywhere).
Better: this dummy process is started once at the beginning of your own
application and thus OpenMutexW should be successful no matter what (if
not we simply exit the OutputToDebugMonitor procedure).
Regards,
Sven
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus