Monday, 28 May 2012

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);




No comments:

Post a Comment