Recent

Author Topic: Cross platform FormatMessage function  (Read 7512 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8831
  • Programming + Glam Metal + Tae Kwon Do = Me
Cross platform FormatMessage function
« on: May 22, 2008, 07:07:04 am »
Is there any cross platform alternative to WINAPI's FormatMessage? I have an IDE project with embedded terminal (made with TCmdBox) with each command is processed by TProcess. Using try-except block where on except I write the exception message, I got (for instance):
Failed to execute XXX : 2
With FormatMessage, I can make it to:
The system cannot find the file specified.
Much clearer, isn't it?
But I don't seem to find the same function for other OSes.

Paul Ishenin

  • Sr. Member
  • ****
  • Posts: 274
RE: Cross platform FormatMessage function
« Reply #1 on: May 26, 2008, 08:35:37 am »
Have you seen rtl Format function?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8831
  • Programming + Glam Metal + Tae Kwon Do = Me
RE: Cross platform FormatMessage function
« Reply #2 on: May 26, 2008, 09:06:29 am »
rtl? Isn't that SysUtils function?

Paul Ishenin

  • Sr. Member
  • ****
  • Posts: 274
RE: Cross platform FormatMessage function
« Reply #3 on: May 27, 2008, 03:17:31 am »
yes

Leledumbo

  • Hero Member
  • *****
  • Posts: 8831
  • Programming + Glam Metal + Tae Kwon Do = Me
RE: Cross platform FormatMessage function
« Reply #4 on: May 27, 2008, 05:47:33 am »
EProcess is raised with that function as the message formatter, I just simply parse the error code after the colon and pass it to FormatMessage.
The error code is system dependent (CMIIW, but does Linux defines 2 as "File not found"?), every OS has its own code for particular error. If only LCL/FCL/RTL has this kind of function, I mean something like:
Code: [Select]

function OSErrorMsg(const ErrorCode: Integer): String;
var
  Buf: PChar;
begin
{$ifdef windows}
FormatMessage(
  ...
)
Result:=StrPas(Buf);
{$else}
...
{$endif}
end;

 

TinyPortal © 2005-2018