Recent

Author Topic: [SOLVED] LCLbase the Identifier not found "FormatMessageA"  (Read 350 times)

d2010

  • Full Member
  • ***
  • Posts: 160
[SOLVED] LCLbase the Identifier not found "FormatMessageA"
« on: April 11, 2025, 02:24:08 am »
I import one copenttd.dpr from delphi.
Inside delphi32 i can compile , but in lazarus many functions not exists
Soo, I emulate many these function/s , bellow here.

C:Q2=I cannot emulate  FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,nil,rc,?


Code: [Select]
function Wind_FindClose(hFindFile: THandle): BOOL; stdcall; external ntdll_kernel32 name 'FindClose';
function Wind_SetConsoleTitle(lpConsoleTitle: PAnsiChar): BOOL; stdcall;external ntdll_kernel32 name 'SetConsoleTitleA';
function wind_GetLastError: DWORD; stdcall;external ntdll_kernel32 name 'GetLastError';
function wind_SendMessage(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; external ntdll_kernel32 name 'SendMessageA';
function wind_SetFileAttributesA(lpFileName: PAnsiChar; dwFileAttributes: DWORD): BOOL; stdcall;external ntdll_kernel32 name 'SetFileAttributesA';

C:Q1=How to erase Wind_* (eg. wind_SetConsoleTitle) and I need
 put the original names?

GetLastError, SetFileAttributesA, FindClose...
Code: [Select]
Library copenttd;
{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}
{$apptype console}


Uses
{$IFnDEF FPC}
  windows,
{$ELSE}
  LCLIntf, LCLType, LMessages,interfaces,
{$ENDIF}
   classes,sysutils,
   hc_exprecon in 'E:\vlaxcompil\Srcincpa\hc_exprecon.pas',
   h_types in 'E:\vlaxcompil\Srcincpa\h_types.pas',
   h_aduiport in 'E:\vlaxcompil\Srcincpa\h_aduiport.pas';
« Last Edit: April 11, 2025, 12:14:30 pm by d2010 »

TRon

  • Hero Member
  • *****
  • Posts: 4351
Re: LCLbase the Identifier not found "FormatMessageA"
« Reply #1 on: April 11, 2025, 06:56:58 am »
Inside delphi32 i can compile , but in lazarus many functions not exists
I am not sure what you are trying to do a) convert the original project to be cross-platform or b) trying to get the original project to compile with Lazarus (without any consideration for cross-platform compatibility)

In case b, all these functions do exist. You just have to know in which unit they are present. The windows unit (which your code explicitly does not use) takes care of most of them and for the rest you can use the jedi units (jwawinbase etc).

In case you are attempting option a then things depend on each individual case the function is used (and use a solution that is in line with how the LCL expects things to be done)
« Last Edit: April 11, 2025, 06:59:34 am by TRon »
Today is tomorrow's yesterday.

d2010

  • Full Member
  • ***
  • Posts: 160
Re: LCLbase the Identifier not found "FormatMessageA"
« Reply #2 on: April 11, 2025, 12:09:51 pm »
In case b, all these functions do exist. You just have to know in which unit they are present. The windows unit (which your code explicitly does not use) takes care of most of them and for the rest you can use the jedi units (jwawinbase etc).

I fixed the function "dfn_GetLoadErrorStr" using jwawinbase.pp
Code: [Select]
Function dfn_GetLoadErrorStr(rc:integer): string;
Var c : integer;
begin
  if (rc=0) then rc := wind_GetLastError;
  SetLength(Result,511);
  C:=FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,nil,rc,
                 dfn_makeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
                 @Result[1], 510,nil);
  SetLength(Result,c);
end;
You ignore the "Uses windows" and you search LANG_NEUTRAL & SUBLANG_DEFAULT), attached bellow ,
Thank you tron == You got  my-solution C:Q2
Thank you tron.
« Last Edit: April 11, 2025, 12:15:17 pm by d2010 »

 

TinyPortal © 2005-2018