[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2127
  • Last Modified:

Delphi to Lazarus?

Hello,

I need to pass a simple Delphi project to compile in Lazarus x64
Since this project when compiled on Delphi x86 doesnt work on a x64 OS

and... as i need to compile on x64 compiler, i'm using Lazarus hehe

take a look at the source!! i tried to compile and searching before but CBT_CreateWnd i can't typecast the lP Param :(

NOTE: I tried to port it from Delphi to Lazarus using Tools > Delphi project to Lazarus Project but no success...

How to make this code working on Lazarus?
Can somebody help me?

Best Regards,
Carlos
(* ORIGINAL DELPHI CODE *)

library uap;

uses
  Windows;

var
  h_HOOK: HHOOK;

{$R *.res}

function StrPas(const Str: PChar): String;
begin
  Result := Str;
end;

function LowerCase(const S: string): string;
var
  Ch: Char;
  L: Integer;
  Source, Dest: PChar;
begin
  L := Length(S);
  SetLength(Result, L);
  Source := Pointer(S);
  Dest := Pointer(Result);
  while L <> 0 do
  begin
    Ch := Source^;
    if (Ch >= 'A') and (Ch <= 'Z') then
    Inc(Ch, 32);
    Dest^ := Ch;
    Inc(Source);
    Inc(Dest);
    Dec(L);
  end;
end;

function CBTProc(nCode: Integer; wP: WPARAM; lP: LPARAM): LRESULT; StdCall;
var
  szBuff: String;
begin  
  try
    if (nCode >= HC_ACTION) then
    begin
      case nCode of
      HCBT_CREATEWND:
      begin
        szBuff := StrPas(PCBTCreateWnd(lp).lpcs.lpszName);
        if (szBuff <> '') then
        if (Pos('notepad', LowerCase(szBuff)) > 0) then
        begin
          //no more notepad
          Result := 1;
          Exit;
        end;
      end;
      end;
    end;
    Result := CallNextHookEx(h_HOOK, nCode, wP, lP); 
  except
    Result := 0;
  end;
end;

function InitUAP: BOOL; StdCall;
begin
  h_HOOK := SetWindowsHookEx(WH_CBT, @CBTProc, SysInit.HInstance, 0);
  Result := LongBool(h_HOOK);                                 
end;

function DeinitUAP: BOOL; StdCall;
begin
  Result := LongBool(h_HOOK);
  if Result then
  Result := UnhookWindowsHookEx(h_HOOK);
end;

exports
  InitUAP name 'InitUAP',
  DeinitUAP name 'DeinitUAP';

end.

Open in new window

0
cebasso
Asked:
cebasso
  • 2
3 Solutions
 
MerijnBSr. Software EngineerCommented:
What is the compiler error you get?
0
 
MvanderKooijCommented:
What parameter is PCBTCreateWnd using?
0
 
cebassoAuthor Commented:
Finally i have done! :D
The error was...
project1.lpr(22,39) Error: Identifier not found "PCBTCreateWnd"
project1.lpr(41,55) Error: Identifier not found "SysInit"
project1.lpr(58) Fatal: There were 2 errors compiling module, stopping
in Delphi is CBTCreateWnd and PCBTCreateWnd and in Lazarus is CBT_CreateWnd and PCBT_CreateWnd... ok, and more one thing... in Delphi isnt needed to use "^" example
szBuff := StrPas(PCBTCreateWnd(lp).lpcs.lpszName);
but in Lazarus is needed...
szBuff := StrPas(PCBT_CreateWnd(lp)^.lpcs^.lpszName);
Project "project1" successfully built. :)
Thank you!!
For me there is no problem and gave points to you, MerjinB and MvanderKooij since you started to help me...
But i dont know if i can, i will see first, before close this topic
Best Regards,
Carlos
0
 
MerijnBSr. Software EngineerCommented:
> in Delphi isnt needed to use "^"

That is because PCBTCreateWnd (or PCBT_CreateWnd) is a pointer to a record. For some reason, in Delphi you can omit the ^ and it will place it there itself. This functionality is not there in Lazarus.

I think it's better to put it there in Delphi too since you are de-reffing a pointer.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now