I have now tried to install a fresh Virtual Machine, and installed Lazarus.
Windows 10, Lazarus 2.2.4 (FPC 3.2.2 with the crosscompile component, so I could change bewteeen Win64/x86_64, Win32/i386 and (Default)/(Default)
Unfortunatley, I was NOT able to reproduce deselico's success on Win64 - it only succedes in Win32.
I tried your code and I get this for Win64/x86_64, Win32/i386 and (Default)/(Default):
=========================
DhcpCApiInitialize: 0
DhcpRequestParams: 0
lan
lan
Windows 11, Lazarus 2.2.4 (rev lazarus_2_2_4) FPC 3.2.2 x86_64-win64-win32/win64
Maybe you should initialize buffer after GetMem:
FillChar(buffer^, size, 0);