I am using this implementation of an icmp ping in delphi. Now i tried to get a human readable error message in case the device was not reachable so that i can print it in the error log.
Can you please explain to me how i can get the human readable error code that is defined here without having to do a switch case and manually writing the strings. I’m fine with using SysErrorMessage, GetIpErrorString or any other WinApi or basic delphi Function if there is one.
I already tried those two methods i found on the internet:
-
SysErrorMessage but that resulted in unrelated text.
-
GetIpErrorString function but im just not getting it to work correctly. My current trials just resulted either in an access violation or a seemingly random byte array.
Current external function definition and method call are like this:
function GetIpErrorString(
const ErrorCode : ULong;
out Buffer : Pointer;
const Size : PDWORD
): DWORD; stdcall; external 'iphlpapi.dll';
var
errorText : string;
bufferSize : Integer;
status : ULong;
ptr : pointer;
begin
// Here is the ping stuff.
// i already verified that this works as the numbers for the
// responseCode are what i would from icmp send error
status := GetLastError();
bufferSize := 200;
GetIpErrorString(
status,
ptr,
@bufferSize
);
SetString(errorText, PChar(ptr), 5);
end
user25427794 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.