DHCP P/Invoke DHCP_IP_ADDRESS issue on 64bit Windows



When using the DHCP-M management protocol from C# you typically define DHCP_IP_ADDRESS as a uint (UInt32) value.

This works correctly on 32bit Windows however when using P/Invoke on a 64bit Windows platform with the host application built as either "Any CPU" or "x64" the application does not work as expected for example you receive the error "The specified subnet does not exist on the DHCP server." when calling the method DhcpGetAllOptionValues.

This is because on 64bit Windows you must define the DHCP_IP_ADDRESS as a UIntPtr value (for example within the structure DHCP_OPTION_SCOPE_INFO) which changes size when run on a 64bit platform.

SubnetScopeInfo = new UIntPtr(SubnetAddress);




Comments

Popular posts from this blog

Windows Server 2016, 2019, 2022, Windows 10 and Windows 11: Date and time "Some settings are managed by your organization".

TFTPD32 or TFTPD64 reports Bind error 10013 An attempt was made to access a socket in a way forbidden by its access permissions.

Enable function lock for F1-F12 on HP ZBook mobile workstations