Archive

Posts Tagged ‘boolean’

How to Resolve a Host Name

December 15th, 1999 m3Rlin No comments

Ever needed to convert a host name to an IP number? There is no direct routine available in Delphi for this but we can always code our way through :-)
Here’s the code with error handling:

uses
  Winsock;
...
// The IP number will be returned in string format in the sIP parameter
function HostToIP(sHost: string; var sIP: string): Boolean;
var
  aHostName: array[0..255] of Char;
  pcAddr   : PChar;
  HostEnt  : PHostEnt;
  wsData   : TWSAData;
begin
  WSAStartup($0101, wsData);
  try
    GetHostName(aHostName, SizeOf(aHostName));
    StrPCopy(aHostName, sHost);
    hostEnt := GetHostByName(aHostName);
    if Assigned(HostEnt) then
      if Assigned(HostEnt^.H_Addr_List) then begin
        pcAddr := HostEnt^.H_Addr_List^;
        if Assigned(pcAddr) then begin
          sIP := Format('%d.%d.%d.%d', [Byte(pcAddr[0]), Byte(pcAddr[1]),
            Byte(pcAddr[2]), Byte(pcAddr[3])]);
          Result := True;
        end else
          Result := False;
      end else
        Result := False
    else begin
      Result := False;
    end;
  finally
    WSACleanup;
  end;
end;

How to Find out if the CPU Supports 3DNow!

December 15th, 1999 m3Rlin No comments

AMD K6-2, K6-III and Athlon support 3DNow! instructions. This instruction set improves 3D and multimedia performance. But before you use these in your program you may want to check if the CPU supports 3DNow! ;-) This is the code to use:

{$ifndef ver80} // Because of 32 bit register use
  function Get3DNowSupport: Boolean; assembler;
  asm
    push  ebx
    mov   @Result, True
    mov   eax, $80000000 // Query for extended fuctions
    dw    $A20F // CPUID instruction
    cmp   eax, $80000000 // Is 800_0001h supported?
    jbe   @NOEXTENDED // If not, 3DNow! technology is not supported
    mov   eax, $80000001 // Setup extended function 8000_0001h
    dw    $A20F // CPUID instruction
    test  edx, $80000000 // Test bit 31
    jnz   @EXIT // 3DNow! technology is supported
  @NOEXTENDED:
    mov  @Result, False
  @EXIT:
    pop ebx
  end;
{$endif}