Recent

Author Topic: Using WriteLn inside dll  (Read 643 times)

DelphiDinosaur

  • New Member
  • *
  • Posts: 25
Using WriteLn inside dll
« on: December 10, 2025, 12:50:09 pm »
I have a com dll that includes the use of WriteLn and Write. These work perfectly when the calling application is a console app, but I get EoleException error Disk full when the code is called from a Windows GUI app - presumably because the WriteLn has no-where to go to.

Short of putting Try..Except around all the calls to WriteLn in the dll code is there a way to avoid the error?

cdbc

  • Hero Member
  • *****
  • Posts: 2616
    • http://www.cdbc.dk
Re: Using WriteLn inside dll
« Reply #1 on: December 10, 2025, 01:05:38 pm »
Hi
Hmmmm, "MichaelSoft BinBows" don't always make things easy, do they?!?
On *nix, there's always a console nearby, not so much on winders...
In fact, as soon as you create a GUI app in winblows, you forego all things console!!!
So, where does that leave us?!?
· writeln is cool, granted, but did you know it has a sibling 'WriteStr'  8)
· if you assign a 'Callback-Function/Procedure' from your host-app to the
  library, so that the library can call that instead of 'writeln', you can let
  'WriteStr' do the formatting and just call
  'SomeCallbackInHost(SomeFormattedString); in the library.
· this alleviates the problem completely, 'cause you can direct the output of
  the callback -> to a commandline via 'Writeln' or a GUI via e.g.: a Tmemo
  on a form...

Anyway, that's how I'm solving conundrums like this... 8-)
Holler if you need more help...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Thausand

  • Sr. Member
  • ****
  • Posts: 458
Re: Using WriteLn inside dll
« Reply #2 on: December 10, 2025, 01:10:29 pm »
@cdbc is not possible and have redirect IO for library ?

Short of putting Try..Except around all the calls to WriteLn in the dll code is there a way to avoid the error?
Write/Writeln have need console. When no console then this make error you see.

Write/Writeln use stdout (https://www.freepascal.org/docs-html/rtl/system/stdout.html) text device (https://docs.freepascal.org/docs-html/rtl/system/textrec.html).

It possible to have assign for redirect. Then can for example have write to file or no write anything. Have thread read for example https://forum.lazarus.freepascal.org/index.php?topic=61765.0

gidesa

  • Full Member
  • ***
  • Posts: 215
Re: Using WriteLn inside dll
« Reply #3 on: December 10, 2025, 01:31:31 pm »
If you want to write some sort of debug message, you can use the Windows function:
OutputDebugString(PWideChar(messageString));
The message string can be a standard one, no special rules.
You can view the debug output with special programs, as DebugView.
https://learn.microsoft.com/it-it/sysinternals/downloads/debugview

DelphiDinosaur

  • New Member
  • *
  • Posts: 25
Re: Using WriteLn inside dll
« Reply #4 on: December 10, 2025, 01:40:00 pm »
Thanks for the suggestions.
I've already switched to using OutputDebugString (Complete with {$IFDEF WINDOWS}).

Looks like a callback function is the way to go longer term.

gidesa

  • Full Member
  • ***
  • Posts: 215
Re: Using WriteLn inside dll
« Reply #5 on: December 10, 2025, 02:06:40 pm »
Yes, the caller can register a callback "writeln" to the Dll, and receive everything that you want, strings and not only.
I don't known if there is in other o.s. (Linux, Macos,..) something as outputdebugstring, maybe there is.


EDIT: indeed there is the Fpc unit systemlog that contains a translation of the (Posix/Unix) system log interface.
« Last Edit: December 10, 2025, 02:20:43 pm by gidesa »

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: Using WriteLn inside dll
« Reply #6 on: December 10, 2025, 04:16:20 pm »
Note that a GUI application can redirect write/writeln and the dll would not have to be adaped. There are several versions to be found on this forum that do that for a memo: TWritelnMemo and consorts, although many are geared towards Interception with Tprocess. That is not necessary, though.
There really is no need for a callback perse although that would work.

Attached is a version from member @Howardpc that would work with write/writeln from a COM dll.
The code needs no changes for that to work with your dll since input/output/erroutput are global so the redirection is also global.

There exist versions that are maybe more refined, but this one is highly understandable.
« Last Edit: December 10, 2025, 07:12:12 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

 

TinyPortal © 2005-2018