Search code examples
delphidllfreepascallazarus

How to block WriteLn() in DLL?


I have a DLL (from the libJasPer project). While decoding an image via jas_image_decode() in my console application the DLL shows a warning on STDOUT.

I looked in JasPer on how to disable warnings but couldn't find anything. How can I block it in Delphi/Lazarus?


Solution

  • You directly or indirectly call jas_conf_clear() which itself sets vlogmsgf to jas_vlogmsgf_stderr by default:

      jas_conf.vlogmsgf = jas_vlogmsgf_stderr;
    

    You have to assign a different function to that variable yourself, f.e. the existing DLL function jas_vlogmsgf_discard():

      jas_conf_set_vlogmsgf( jas_vlogmsgf_discard );
    

    ...or by providing your very own function, which does its own thing when called:

    type
      jas_logtype_t= Cardinal;
    
    function jas_vlogmsgf_myown( typ: jas_logtype_t; const fmt: PAnsiChar; ap: Array of Const ): Integer; cdecl;
    

    ...whereas using Array of Const for va_list is just a wild guess by me - this could go horribly wrong. The documentation deals with this at JasPer Library > Configuration, Initialization, and Shutdown in both sections: