Windows 清除DNS缓存C++实现

一 代码

#include 
#include 

typedef BOOL (WINAPI *DnsFlushResolverCacheFuncPtr)();


int main() {
    HMODULE dnsapi = LoadLibrary("dnsapi.dll");
    if (dnsapi == NULL) {
        printf("Failed loading module: %d\n", GetLastError());
        return -1;
    }
    DnsFlushResolverCacheFuncPtr DnsFlushResolverCache = 
          (DnsFlushResolverCacheFuncPtr)GetProcAddress(dnsapi, "DnsFlushResolverCache");
    if (DnsFlushResolverCache == NULL) {
        printf("Failed loading function: %d\n", GetLastError());
        FreeLibrary(dnsapi);
        return -2;
    }
    BOOL result = DnsFlushResolverCache();
    if (result) {
        printf("DnsFlushResolverCache succeeded\n");
    } else {
        printf("DnsFlushResolverCache succeeded: %d\n", GetLastError());
    }
    FreeLibrary(dnsapi);
    return 0;
}

二 链接

stackoverflow - How to Clear/Flush the DNS Cache in Win32 API's

你可能感兴趣的:(#,C++98/03,#,Windows)