• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1387
  • Last Modified:

flushdns

I need to clear the DNS cache and I don't want to use "ipconfig /flushdns".
It looks like dnsapi.dll can be used for that but I can't find any Delphi code example.
Below is a C language example.
I'd like to have the same function for Delphi 7.
Thanks.

BOOL DnsFlushResolverCache()
{
   BOOL (WINAPI *DoDnsFlushResolverCache)();
   *(FARPROC *)&DoDnsFlushResolverCache = GetProcAddress(LoadLibrary("dnsapi.dll"), "DnsFlushResolverCache");
   if(!DoDnsFlushResolverCache) return FALSE;
   return DoDnsFlushResolverCache();
}

Open in new window

0
3axap
Asked:
3axap
2 Solutions
 
DerZaubererCommented:
The above should be the declaration.

unit

...

interface

...

implementation

{ declaration }
Function DnsFlushResolverCache: DWord; stdcall; external 'dnsapi.dll';

...

{ call it }
procedure CallIt;
begin
  { call it, ignore return code }
  DnsFlushResolverCache;
end;
0
 
rotem156Commented:
You're welcome.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now