[SOLVED] Default to the W Alias inside the Windows unit? lazarus / 67-Windows ---------------------------------------------------------------------- KodeZwerg · 2023-04-11 23:57 Good day. How do I tell my project that it use the W Aliases from the Windows API instead of the A Aliases? By looking inside of Windows.pp I do see: 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 {$ifdef FPC_OS_UNICODE}  {$define UNICODE}{$endif} followed later by {$ifdef UNICODE}{$i unidef.inc}{$else not UNICODE}{$i ascdef.inc}{$endif UNICODE} By doing: 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;{$DEFINE FPC_OS_UNICODE}{$DEFINE UNICODE}{$mode delphiunicode}{$modeswitch m_default_unicodestring} It still points me to the Ansi versions, but I want the Wide versions to be used without adding "W" to the API methods. Quote{$DEFINE FPC_OS_UNICODE} {$define UNICODE}inside Project Options / Custom Options / Conditionals       has also no effect. Also the -WA switch has no effect. What is the correct way of how it should be done please? Answers that telling me to simply put a W at end I really not need to get. Thanks in advance! (At the end I want to have this behavior: a ctrl+click on "GetBinaryType" jumps into unidef.inc and of course uses it also) ---------------------------------------------------------------------- KodeZwerg · 2023-04-12 00:01 Sorry, I forgot to tell, I am using Lazarus 2.3.0 (rev 3bdbedd91b) FPC 3.2.2 x86_64-win64-win32/win64 on a Windows 10 64bit machine. ---------------------------------------------------------------------- KodeZwerg · 2023-04-12 00:04 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;{$DEFINE FPC_OS_UNICODE}{$DEFINE UNICODE}{$mode delphiunicode}{$modeswitch m_default_unicodestring} interface uses  Windows ,  Classes , SysUtils , Forms , Controls , Graphics , Dialogs; type   { TForm1 }   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  // next line is my test line, a ctrl+click should point me to the unidef.inc declaration  // how to do that please?  GetBinaryTypeend; end. ---------------------------------------------------------------------- marcov · 2023-04-12 07:44 There currently is no easy way.  While the Windows has some ifdef work, but probably too many other units depend on it being one byte, to simply enable it and recompile everything. ---------------------------------------------------------------------- tetrastes · 2023-04-12 08:39 Quote from: KodeZwerg on April 12, 2023, 01:57:35 amGood day. How do I tell my project that it use the W Aliases from the Windows API instead of the A Aliases? By looking inside of Windows.pp I do see: 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 {$ifdef FPC_OS_UNICODE}  {$define UNICODE}{$endif} followed later by {$ifdef UNICODE}{$i unidef.inc}{$else not UNICODE}{$i ascdef.inc}{$endif UNICODE} But at the second line below there is 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 {$i redef.inc} and in redef.inc 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 function GetBinaryType(lpApplicationName: PChar; var lpBinaryType: DWORD): BOOL;external 'kernel32' name 'GetBinaryTypeA'; ---------------------------------------------------------------------- KodeZwerg · 2023-04-12 09:24 Quote from: marcov on April 12, 2023, 09:44:18 amThere currently is no easy way.  While the Windows has some ifdef work, but probably too many other units depend on it being one byte, to simply enable it and recompile everything.Thank you for your answer! It's a little bit confusing why I can't activate it. For the moment I patched the "Windows.pp" and added 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 {$define FPC_OS_UNICODE} // this was added by me infront of the conditional UNICODE define {$ifdef FPC_OS_UNICODE}  {$define UNICODE}{$endif}I hope that I do not break anything by doing so... Quote from: tetrastes on April 12, 2023, 10:39:20 amBut at the second line below there is 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 {$i redef.inc} and in redef.inc 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 function GetBinaryType(lpApplicationName: PChar; var lpBinaryType: DWORD): BOOL;external 'kernel32' name 'GetBinaryTypeA';Thank you for your answer! I do not really understand your reply, my goal is/was to get 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 function GetBinaryType(lpApplicationName:LPCWSTR; lpBinaryType:LPDWORD):WINBOOL; external 'kernel32' name 'GetBinaryTypeW'; (I just used exemplary the very first declaration, of course I do mean all "W" variants.) ---------------------------------------------------------------------- marcov · 2023-04-12 11:10 After changes to windows unit, you must recompile the whole of FPC+lazarus, as many unit direct or indirectly will depend on windows.pp redef.inc is a place where prototypes are placed that Delphi translated differently than most. Probably it needs work for unicode to work properly (the $ifdef unicode structure in the other files is from the windows headers) ---------------------------------------------------------------------- tetrastes · 2023-04-12 14:07 Quote from: KodeZwerg on April 12, 2023, 11:24:34 amQuote from: tetrastes on April 12, 2023, 10:39:20 amBut at the second line below there is 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 {$i redef.inc} and in redef.inc 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 function GetBinaryType(lpApplicationName: PChar; var lpBinaryType: DWORD): BOOL;external 'kernel32' name 'GetBinaryTypeA';Thank you for your answer! I do not really understand your reply, I meant that a ctrl+click jumps there by default (i.e. parameters types do not match exactly to those in ascdef.inc or unidef.inc), as in your example: 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 TForm1.FormCreate(Sender: TObject);begin  // next line is my test line, a ctrl+click should point me to the unidef.inc declaration  // how to do that please?  GetBinaryTypeend;  But now I see that the main problem is not in this. I managed to do what you want with this ugly hack: 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 delphi} - is not compiled{$mode objfpc}  // windows.pp is in {$mode objfpc}//{$modeswitch unicodestrings} - with this works also interface uses  Windows ,  Classes , SysUtils , Forms , Controls , Graphics , Dialogs; {$define read_interface}{$undef read_implementation}{$i C:\lazarus\fpc\3.2.2\source\rtl\win\wininc\unidef.inc} type   { TForm1 }   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$undef read_interface}{$define read_implementation}{$i C:\lazarus\fpc\3.2.2\source\rtl\win\wininc\unidef.inc} {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);var    lpApplicationName: PWideChar; //or LPCWSTR;    lpBinaryType: LPDWORD;begin  // next line is my test line, a ctrl+click should point me to the unidef.inc declaration  // how to do that please?  GetBinaryType(lpApplicationName, lpBinaryType);end; end. It is even compiled (but not in mode delphi, note that windows.pp is in mode objfpc) and runs. ---------------------------------------------------------------------- 440bx · 2023-04-12 14:20 Disclaimer: I haven't tried this therefore I don't know if it works or not. If I were you I'd try creating a new installation using FPCUPDELUXE with the proper defines activated.  At least in theory and, with properly activated defines, that installation would default to the "W" functions. HTH. ---------------------------------------------------------------------- KodeZwerg · 2023-04-12 14:37 Quote from: 440bx on April 12, 2023, 04:20:16 pmDisclaimer: I haven't tried this therefore I don't know if it works or not. If I were you I'd try creating a new installation using FPCUPDELUXE with the proper defines activated.  At least in theory and, with properly activated defines, that installation would default to the "W" functions. HTH. Thanks for your response! I did asked about that switch but did not get any answer. So what I try to say, it wont install/compile. But maybe you mean something different than the "Unicode"-Checkbox within setup of FpcUpdeluxe. Quote from: tetrastes on April 12, 2023, 04:07:21 pmIt is even compiled (but not in mode delphi, note that windows.pp is in mode objfpc) and runs.  Thank you for your "hack", I like, love and use it! Way better than patching and messing around in the RTL  Quote from: marcov on April 12, 2023, 01:10:04 pmAfter changes to windows unit, you must recompile the whole of FPC+lazarus, as many unit direct or indirectly will depend on windows.pp redef.inc is a place where prototypes are placed that Delphi translated differently than most. Probably it needs work for unicode to work properly (the $ifdef unicode structure in the other files is from the windows headers) Again thank you very much for your help! ---------------------------------------------------------------------- 440bx · 2023-04-12 15:23 Quote from: KodeZwerg on April 12, 2023, 04:37:49 pmI did asked about that switch but did not get any answer. So what I try to say, it wont install/compile. But maybe you mean something different than the "Unicode"-Checkbox within setup of FpcUpdeluxe. I don't know what effect the "unicode" checkbox has in fpcupdeluxe.  If memory serves, there is a place in fpcupdeluxe where one can _manually_ specify defines and compiler switches to be passed to the compiler.  If I am not mistaken and, that is correct, that's what I'd try. Lastly, one comment.  From what you've said you're doing this because you don't want to hardcode the "A" or "W" of the Windows function being used.  Personally, I prefer hardcoding the "W" because it removes all possible ambiguities and serves as documentation. It's different in C because in C, everything gets either re-wired (in the case of some libraries) or recompiled to ensure consistency, that is not the case in FPC.