[SOLVED] WINAPI DhcpRequestParams works in 32-bit, but returns error 87in 64bit lazarus / 67-Windows ---------------------------------------------------------------------- tboege · 2022-10-18 08:57 Solved in https://forum.lazarus.freepascal.org/index.php/topic,60922.m sg457312.html#msg457312 Crosspost: This is almost identical to "Lazarus »Forum »Programming »Operating Systems »Windows »Getting error (87) when calling DhcpRequestParams" I hope, that somebody in this subforum can help. Crosscompile for 32-bit: The code works fine: returnvalue from DhcpRequestParams is 0 - and the data in buffer and RecdParams.Params[0].Data is valid. Compile for Target (Default) , ie 64 bit: I get returnvalue from DhcpRequestParams "ERROR_INVALID_PARAMETER" (ie 87) and the data in buffer and RecdParams.Params[0].Data is NOT valid. 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.Button1Click(Sender: TObject);var  Adaptername: PWCHAR;  SendParams, RecdParams: DHCPCAPI_PARAMS_ARRAY;  option15param: DHCPCAPI_PARAMS;  buffer: LPBYTE;  size, StatusI, StatusR, dwVersion: DWORD;begin  Memo1.Lines.Add('=========================');  size := 1024;  GetMem(buffer, size);  Adaptername := '{C90A9165-BE89-49AC-B79C-B2F6D5DF7B91}';  option15param.OptionId := OPTION_DOMAIN_NAME;  option15param.IsVendor := False;  option15param.Data := nil;  option15param.nBytesData := 0;  option15param.Flags := 0;    RecdParams.nParams := 1;  RecdParams.Params := @option15param;  SendParams.Params := nil;  SendParams.nParams := 0;   StatusI := DhcpCApiInitialize(dwVersion);  Memo1.Lines.Add('DhcpCApiInitialize: ' + IntToStr(StatusI));   StatusR := DhcpRequestParams(DHCPCAPI_REQUEST_SYNCHRONOUS, LPVOID(nil),    Adaptername, nil, SendParams, RecdParams, buffer, @size, nil);  Memo1.Lines.Add('DhcpRequestParams: ' + IntToStr(StatusR));  Memo1.Lines.Add(StrPas(PChar(buffer)));  Memo1.Lines.Add(StrPas(PChar(RecdParams.Params[0].Data)));  if StatusI = 0 then DhcpCApiCleanup();  FreeMem(buffer, size); end; ---------------------------------------------------------------------- dseligo · 2022-10-18 09:33 I tried your code and I get this for Win64/x86_64, Win32/i386 and (Default)/(Default): Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i =========================DhcpCApiInitialize: 0DhcpRequestParams: 0lanlan 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: 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 FillChar(buffer^, size, 0); ---------------------------------------------------------------------- dseligo · 2022-10-18 09:59 Do you have correct GUID of your network adapter (connected to network)? You can get it with: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i netsh wlan show interfaces or Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i netsh lan show interfaces ---------------------------------------------------------------------- tboege · 2022-10-18 10:04 Thank you for your efford. Out different results makes it really strange. I am running the same version of Lazarus/FPC. I guess I have the right adaptername, since it works in Win32. The output of  netsh lan show interfaces: Code: [Select] S C:\WINDOWS\system32> netsh wlan show interfaces There is 1 interface on the system:     Name                   : Wi-Fi     Description            : Intel(R) Dual Band Wireless-AC 8265     GUID                   : c90a9165-be89-49ac-b79c-b2f6d5df7b91     Physical address       : 34:41:5d:45:b4:10     Interface type         : Primary     State                  : connected     SSID                   : nelson_5G     BSSID                  : d6:6e:0e:36:eb:1e     Network type           : Infrastructure     Radio type             : 802.11ac     Authentication         : WPA2-Personal     Cipher                 : CCMP     Connection mode        : Auto Connect     Band                   : 5 GHz     Channel                : 44     Receive rate (Mbps)    : 400     Transmit rate (Mbps)   : 400     Signal                 : 91%     Profile                : nelson_5G     Hosted network status  : Not available Maybee I should another installation of Lazarus on virtual computer. ---------------------------------------------------------------------- marcov · 2022-10-18 10:07 Maybe DHCPCAPI_PARAMS_ARRAY isn't 64-bit proof ? where is this defined? Keep in mind that Jedi units are generally not 64-bit proof ! ---------------------------------------------------------------------- tboege · 2022-10-18 10:23 DHCPCAPI_PARAMS_ARRAY  is defined in JwaDhcpCSdk - a part of Jedi. I was not aware, that Jedi units generally not are 64-bit proof. If that is the problem, it is strange, that sdeligo had no problems in 64bit. ---------------------------------------------------------------------- tboege · 2022-10-18 10:39 I have now had a brief look at the definitions in JwaDhcpCSdk  and tried to compare to https://learn.microsoft.com/en- us/windows/win32/api/dhcpcsdk/nf-dhcpcsdk-dhcprequestparams and the links to DHCPCAPI_PARAMS_ARRAY and to DHCPCAPI_PARAMS . I cannot figure out, if there are any important differences - I'm afraid I dont have the skills. ---------------------------------------------------------------------- tboege · 2022-10-18 13:53 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. Quote from: dseligo on October 18, 2022, 11:33:39 amI tried your code and I get this for Win64/x86_64, Win32/i386 and (Default)/(Default): Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i =========================DhcpCApiInitialize: 0DhcpRequestParams: 0lanlan 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: 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 FillChar(buffer^, size, 0); ---------------------------------------------------------------------- tboege · 2022-10-19 19:43 Thank you for your effort. The solution was to replace jwaWindows with jwadhcpcsdk as suggested by Aserge in https://forum.lazarus.freepascal.org/index.php?topic=6092 2.msg457312#msg457312