Windows 清除DNS缓存C++实现

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 20:26   2733   0

一 代码

#include <stdio.h>
#include <Windows.h>

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

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP