Recent

Author Topic: [SOLVED] WINAPI DhcpRequestParams works in 32-bit, but returns error 87in 64bit  (Read 1286 times)

tboege

  • New Member
  • *
  • Posts: 16
Solved in https://forum.lazarus.freepascal.org/index.php/topic,60922.msg457312.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][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   Adaptername: PWCHAR;
  4.   SendParams, RecdParams: DHCPCAPI_PARAMS_ARRAY;
  5.   option15param: DHCPCAPI_PARAMS;
  6.   buffer: LPBYTE;
  7.   size, StatusI, StatusR, dwVersion: DWORD;
  8. begin
  9.   Memo1.Lines.Add('=========================');
  10.   size := 1024;
  11.   GetMem(buffer, size);
  12.   Adaptername := '{C90A9165-BE89-49AC-B79C-B2F6D5DF7B91}';
  13.   option15param.OptionId := OPTION_DOMAIN_NAME;
  14.   option15param.IsVendor := False;
  15.   option15param.Data := nil;
  16.   option15param.nBytesData := 0;
  17.   option15param.Flags := 0;
  18.  
  19.  
  20.   RecdParams.nParams := 1;
  21.   RecdParams.Params := @option15param;
  22.   SendParams.Params := nil;
  23.   SendParams.nParams := 0;
  24.  
  25.   StatusI := DhcpCApiInitialize(dwVersion);
  26.   Memo1.Lines.Add('DhcpCApiInitialize: ' + IntToStr(StatusI));
  27.  
  28.   StatusR := DhcpRequestParams(DHCPCAPI_REQUEST_SYNCHRONOUS, LPVOID(nil),
  29.     Adaptername, nil, SendParams, RecdParams, buffer, @size, nil);
  30.   Memo1.Lines.Add('DhcpRequestParams: ' + IntToStr(StatusR));
  31.   Memo1.Lines.Add(StrPas(PChar(buffer)));
  32.   Memo1.Lines.Add(StrPas(PChar(RecdParams.Params[0].Data)));
  33.   if StatusI = 0 then DhcpCApiCleanup();
  34.   FreeMem(buffer, size);
  35.  
  36. end;
  37.  
« Last Edit: October 19, 2022, 09:39:33 pm by tboege »

dseligo

  • Hero Member
  • *****
  • Posts: 1220
I tried your code and I get this for Win64/x86_64, Win32/i386 and (Default)/(Default):
Code: Text  [Select][+][-]
  1. =========================
  2. DhcpCApiInitialize: 0
  3. DhcpRequestParams: 0
  4. lan
  5. 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:
Code: Pascal  [Select][+][-]
  1. FillChar(buffer^, size, 0);

dseligo

  • Hero Member
  • *****
  • Posts: 1220
Do you have correct GUID of your network adapter (connected to network)?

You can get it with:
Code: Text  [Select][+][-]
  1. netsh wlan show interfaces

or

Code: Text  [Select][+][-]
  1. netsh lan show interfaces

tboege

  • New Member
  • *
  • Posts: 16
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

  • Administrator
  • Hero Member
  • *
  • Posts: 11447
  • FPC developer.
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

  • New Member
  • *
  • Posts: 16
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

  • New Member
  • *
  • Posts: 16
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

  • New Member
  • *
  • Posts: 16
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):
Code: Text  [Select][+][-]
  1. =========================
  2. DhcpCApiInitialize: 0
  3. DhcpRequestParams: 0
  4. lan
  5. 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:
Code: Pascal  [Select][+][-]
  1. FillChar(buffer^, size, 0);

tboege

  • New Member
  • *
  • Posts: 16
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=60922.msg457312#msg457312

 

TinyPortal © 2005-2018