How to define OS version on compilation stage? lazarus / 34-Windows ---------------------------------------------------------------------- anna · 2015-07-02 17:22 I need to use Windows7 specific function declaration when application is used on Win7 and do not use, when it runs on WinXP Code: [Select]type   DYNAMIC_TIME_ZONE_INFORMATION = record        Bias : LONG;        StandardName : array[0..31] of WCHAR;        StandardDate : SYSTEMTIME;        StandardBias : LONG;        DaylightName : array[0..31] of WCHAR;        DaylightDate : SYSTEMTIME;        DaylightBias : LONG;        TimeZoneKeyName:array[0..127] of WCHAR;        DynamicDaylightTimeDisabled:boolean;     end;   LPDYNAMIC_TIME_ZONE_INFORMATION = ^DYNAMIC_TIME_ZONE_INFORMATION; function SetDynamicTimeZoneInformation(lpDynamicTimeZoneInformation:LP DYNAMIC_TIME_ZONE_INFORMATION):WINBOOL; external 'kernel32' name 'SetDynamicTimeZoneInformation'; But when I start it on WinXP , I get error "Entry point of SetDynamicTimeZoneInformation not found in kernel32.dll". WinXP's kernel32 has not this API. So I need some thing like if-then- else statement with version detection bun outside of begin-end block. What should I do? ---------------------------------------------------------------------- ChrisF · 2015-07-02 17:29 In SysUtils: - function CheckWin32Version(Major,Minor : Integer ): Boolean; - or directly using the Win32MajorVersion, Win32MinorVersion variables. Anyway, you'll also need to dynamically load this function from the kernel32 .dll (i.e. you can't use a static binding in your case). ---------------------------------------------------------------------- anna · 2015-07-02 17:36 Quote from: ChrisF on July 02, 2015, 07:29:56 pmIn SysUtils: - function CheckWin32Version(Major,Minor : Integer ): Boolean; - or directly using the Win32MajorVersion, Win32MinorVersion variables. Anyway, you'll also need to dynamically load this function from the kernel32 .dll (i.e. you can't use a static binding in your case). Do you mean GetProcAddress? Can you give piece of code? ---------------------------------------------------------------------- ChrisF · 2015-07-02 17:58 Quote from: anna on July 02, 2015, 07:36:27 pmDo you mean GetProcAddress? Can you give piece of code? Thats' it. A basic sample: Code: [Select]uses   ..., Windows; procedure TForm1.Button1Click(Sender: TObject); var PAddrGetDiskFreeSpaceExW: function(lpDirectoryName: LPCWSTR; var lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes: int64): BOOL; stdcall; var FreeSpaceAvailable, TotalSpace, AllFree: int64; begin   FARPROC(PAddrGetDiskFreeSpaceExW) :=     GetProcAddress(GetModuleHandle('kernel32.dll'), 'GetDiskFreeSpaceExW');   if Assigned(PAddrGetDiskFreeSpaceExW) then     begin       // Your code...       PAddrGetDiskFreeSpaceExW('C:\', FreeSpaceAvailable, TotalSpace, AllFree);       ShowMessage('Function Found: FreeSpace for Disk C='+IntToStr(FreeSpaceAvailable));     end   else     ShowMessage('** Error** Function NOT Found'); end; It's valid for {$mode objfpc}. In case of {$mode delphi}, use @xxxx instead of FARPROC(xxxx). ---------------------------------------------------------------------- anna · 2015-07-02 19:56 I found little different example : http://wiki.freepascal.org/DLL_dynamically_load/de . ---------------------------------------------------------------------- ChrisF · 2015-07-02 20:19 No, it's in fact the same thing. This only difference is that the system .dll "kernel32.dll" is already loaded into your application (unless you've got a very specific one; I'm not even sure it's possible with FPC or any Windows executable ?). Anyway, concretely it means that you don't need to load it. The rest of the code is then identical, once you've loaded it and get a Handle on it. While your link deals with a user's dll: which you'll usually have to load before using it. ** Edit ** And according to your first post, you need to get a function from the "kernel32.dll"; so, my sample...