[SOLVED] Getting error (87) when calling DhcpRequestParams lazarus / 34-Windows ---------------------------------------------------------------------- tboege · 2022-10-17 00:22 I am trying to get me head around some relatively simple api-calls. But I cannot really succeed. When ever I call the DhcpRequestParams in the routine below, I get status=87 (=ERROR_INVALID_PARAMETER), which should refer to AdapterName longer than 256 chars according to https://learn.microsoft.com/en-us/windows/win32/api/dhcpcsdk/nf- dhcpcsdk-dhcprequestparams. Can  you see, what I am doing wrong? 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: pbyte;  size, Status: DWORD; begin  size := 1024;  GetMem(buffer, size);  Adaptername := '{C90A9165-BE89-49AC-B79C-B2F6D5DF7B91}';  option15param.Flags := 0;  option15param.OptionId := OPTION_DOMAIN_NAME;  option15param.IsVendor := False;  option15param.Data := nil;  option15param.nBytesData := 0;  RecdParams.nParams := 1;  RecdParams.Params := @option15param;  SendParams.Params := nil;  SendParams.nParams := 0;     Status := DhcpRequestParams(DHCPCAPI_REQUEST_SYNCHRONOUS, nil, Adaptername,    nil, SendParams, RecdParams, buffer, @size, nil);  Memo1.Lines.Add(StrPas(PChar(buffer)));  Button1.Caption := IntToStr(Status); end; ---------------------------------------------------------------------- tboege · 2022-10-17 11:48 I figured out, the code works as expected, when I compile for 32bit windows - but I only get the status=87 when compiling for 64 bit ---------------------------------------------------------------------- ASerge · 2022-10-19 00:36 Quote from: tboege on October 17, 2022, 02:22:21 amCan  you see, what I am doing wrong? Could there be an incorrect adapter name? I don't use DHCP, but this code is executed without errors (gives, of course, an empty domain name): 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 uses Windows, jwadhcpcsdk, jwaiptypes, jwaiphlpapi; function RetrieveDomaintName(AdapterName: PWideChar): string;var  Buffer: array[0..1000] of Byte;  DomainNameParams: DHCPCAPI_PARAMS;  RequestParams: DHCPCAPI_PARAMS_ARRAY;  SendParams: DHCPCAPI_PARAMS_ARRAY;  Size: DWORD = SizeOf(Buffer);  Status: DWORD;begin  Result := '';  ZeroMemory(@DomainNameParams, SizeOf(DomainNameParams));  DomainNameParams.Flags := OPTION_DOMAIN_NAME;  ZeroMemory(@SendParams, SizeOf(SendParams));  RequestParams.nParams := 1;  RequestParams.Params := @DomainNameParams;  Status := DhcpRequestParams(DHCPCAPI_REQUEST_SYNCHRONOUS, nil,    AdapterName, nil, SendParams, RequestParams, @Buffer, @Size, nil);  if Status <> 0 then    RaiseLastOSError(Status);  SetString(Result, PChar(DomainNameParams.Data), DomainNameParams.nBytesData);end; procedure TForm1.Button1Click(Sender: TObject);var  Version: DWORD;  BufSize: ULONG;  P, Buffer: PIP_ADAPTER_INFO;  AdapterName: UnicodeString;begin  if DhcpCApiInitialize(Version) <> 0 then    Exit;  try    BufSize := 0;    if GetAdaptersInfo(nil, BufSize) <> ERROR_BUFFER_OVERFLOW then      RaiseLastOSError;    GetMem(Buffer, BufSize);    try      if GetAdaptersInfo(Buffer, BufSize) <> 0 then      RaiseLastOSError;      P := Buffer;      repeat        AdapterName := P^.AdapterName;        Memo1.Append(RetrieveDomaintName(Pointer(AdapterName)));        P := P^.Next;      until P = nil;    finally      FreeMem(Buffer);    end;  finally    DhcpCApiCleanup;  end;end; ---------------------------------------------------------------------- tboege · 2022-10-19 19:37 I have tried you code. It seems to work in both 32-bit and 64-bit. I had to replace line 14 with 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 DomainNameParams.Flags := 0;DomainNameParams.OptionId := OPTION_DOMAIN_NAME;   (That could be the reason, why you didnt get a domain name) I have compared your solution with my code, and found, that my cod works, if I replace the uses:   JwaWindows;   with  jwadhcpcsdk; Thank you, very much - if you have an explanation, why jwaWindows not works in 64bit, but works in 32bit, but have to be replaced with jwadhcpcsdk , I would like to know. ---------------------------------------------------------------------- ASerge · 2022-10-19 20:03 Quote from: tboege on October 19, 2022, 09:37:07 pmI had to replace line 14 with Thanks for the correction Quote(That could be the reason, why you didnt get a domain name) I don't get it because I don't use it. I have static and no domain. QuoteThank you, very much - if you have an explanation, why jwaWindows not works in 64bit, but works in 32bit, but have to be replaced with jwadhcpcsdk , I would like to know. The jwaWindows unit is a container for all jwa units, including jwadhcpcsdk. I think the problem is that one of the included units activates the packing of records, which makes the structure DHCPCAPI_PARAMS not 32 bytes, but only 24. ---------------------------------------------------------------------- tboege · 2022-10-20 08:39 I think you are rigth. I have checked with SizeOf(DHCPCAPI_PARAMS). I have also tried to add {$PACKRECORDS  C} before the definition af the record i jwadhcpcsdk and recompile Jedi. With that addition, it works even when I use JwaWindows. But since I don't know, if it gives any sideeffects, I will just stick to jwadhcpcsdk. Should this be reported as a bug to the maintainers of Jedi (if there ara any)? ---------------------------------------------------------------------- PascalDragon · 2022-10-21 14:09 Quote from: tboege on October 20, 2022, 10:39:35 amShould this be reported as a bug to the maintainers of Jedi (if there ara any)? It should be reported as a bug on our own bug tracker, because the Jedi units have been imported from the Jedi project a long time ago and were modified since then.