[SOLVED] Port RegisterHotKey from 32bit to 64bit lazarus / 34-Windows ---------------------------------------------------------------------- tboege · 2022-10-13 09:47 I am running Lazarus 2.2.0 on 64 bit Windows. I can compile and run the program below, when I compile in 32-bit mode (Target OS Win32, Target CPU family i386, Target processor (Default), but when I change to 64-bit (Targget OS, Target CPU family, Target processor, alle (Default), then program still runs. I still get avalue fra HotKeyDebugWindow around 4565 (a relatively low number), but in  TForm1.OnHotKey Msg.HotKey  is a very high number ( eg 213008903045120), which is not identical to HotKeyDebugWindow. Can anyone help? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Windows; type  TWMHotKey = packed record    MSG: cardinal;    HotKey: PtrInt;    Unused: PtrInt;    Result: PtrInt;  end;  { TForm1 }   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);  private    procedure OnHotKey(var Msg: TWMHotKey); message WM_HOTKEY;   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 }var  HotKeyDebugWindow: NativeInt; procedure TForm1.FormCreate(Sender: TObject);var  Result: longbool;begin  HotKeyDebugWindow := GlobalAddAtom('Hotkey: SHITCTRLE');  Result := RegisterHotkey(Handle, HotKeyDebugWindow, MOD_CONTROL + MOD_SHIFT, Ord('E'));  ShowMessage(BoolToStr(result));end; procedure TForm1.OnHotKey(var Msg: TWMHotKey);begin  if Msg.HotKey = HotKeyDebugWindow then  begin    ShowMessage('test');  end;end; end. ---------------------------------------------------------------------- Remy Lebeau · 2022-10-13 20:17 Related: TWMKey(Message) cast doesn't work on Win64 Your TWMHotKey record is not declared correctly for 64bit.  You are removing all alignment padding in between the record's fields, but that padding is actually required to line up the fields correctly. This is how Delphi declares its own TWMHotKey: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TWMHotKey = record    Msg: Cardinal;    MsgFiller: TDWordFiller;    HotKey: WPARAM;    Unused: LPARAM;    Result: LRESULT;  end; Where TDWordFiller is 0 bytes on 32bit and 4 bytes on 64bit.  I don't know if TDWordFiller was ever incorporated into FPC, but if not then you can try this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TWMHotKey = record    Msg: Cardinal;{$ifdef cpu64}    MsgFiller: Cardinal;{$endif}    HotKey: WPARAM;    KeyData: LPARAM;    Result: LRESULT;  end; Or, you could simply not use TWMHotKey at all: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure OnHotKey(var Msg: TMessage); message WM_HOTKEY;...procedure TForm1.OnHotKey(var Msg: TMessage);begin  if Msg.WParam = HotKeyDebugWindow then  begin    ShowMessage('test');  end;end; Also, on a side note: GlobalAddAtom() returns an ATOM, which is a WORD, not a NativeInt.  And RegisterHotKey() takes an Integer id, not a NativeInt id. ---------------------------------------------------------------------- tboege · 2022-10-14 08:33 Thank you, Remy. That solved my problem. BTW, TDWordFiller is defined in Lazarus, so I just used the Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TWMHotKey = record    Msg: Cardinal;    MsgFiller: TDWordFiller;    HotKey: WPARAM;    Unused: LPARAM;    Result: LRESULT;  end;  I will now dig into GetAdaptersInfo from  JwaIpHlpApi and DhcpRequestParams  JwaDhcpCSdk. Since I (obviously) not are familiar with Win32 API - can you point me in a direction to learn about Win32 API and FPC?