windows LoadLibrary使用示例

typedef int(*HA_GetVersion_t)(); //定义函数指针类型

void TestLoadDll()
{
    HINSTANCE hDll; //DLL句柄

    TCHAR chCurDir[MAX_PATH] = {0};
    GetCurrentDirectory(MAX_PATH, chCurDir);
    SetCurrentDirectory(_T("E:\\libHasdk\\dll"));

    hDll = LoadLibrary(_T("libHasdk.dll"));

    SetCurrentDirectory(chCurDir);

    if (hDll != NULL)
    {

        HA_GetVersion_t HA_GetVersion_p = NULL;

        HA_GetVersion_p = (HA_GetVersion_t)GetProcAddress(hDll, "HA_GetVersion");

        if (HA_GetVersion_p != NULL)
        {
            int version = HA_GetVersion_p();
            printf("version = %d\n", version);
        }
        else
        {
            printf("the calling is error\n");
        }

        FreeLibrary(hDll);

    }
    else
    {
        printf("Load DLL Error or DLL not exist!\n");
    }
}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页