【问题标题】:c++ loadlibrary - import dllc++ loadlibrary - 导入dll
【发布时间】:2018-02-05 21:10:22
【问题描述】:

你能告诉我这个 c++ 代码有什么问题吗?它总是返回 E_INVALIDARG

typedef HRESULT STDAPICALLTYPE AcquireDeveloperLicense(
    _In_opt_ HWND     hwndParent,
    _Out_    FILETIME *pExpiration
    );
HINSTANCE hDll = LoadLibrary(TEXT("WSClient.dll"));
AcquireDeveloperLicense *acquire_license = (AcquireDeveloperLicense*)GetProcAddress(hDll, "AcquireDeveloperLicense");
FILETIME *pExpiration = NULL;
HWND hwnd = GetConsoleWindow();
HRESULT result = acquire_license(hwnd, pExpiration);

【问题讨论】:

  • 错误信息告诉你出了什么问题。其中一个论点无效。您是否查看了错误代码并认为它​​可能暗示什么?

标签: c++ visual-studio winapi


【解决方案1】:

您在AcquireDeveloperLicense() 的第二个参数中传递了一个NULL 指针。它希望您传递指向FILETIME 结构的指针以接收许可证的到期日期。 FILETIME 不是可选的。

试试这个:

typedef HRESULT (STDAPICALLTYPE *LPFN_AcquireDeveloperLicense)(
    _In_opt_ HWND     hwndParent,
    _Out_    FILETIME *pExpiration
    );

HINSTANCE hDll = LoadLibrary(TEXT("WSClient.dll"));
if (hDll)
{
    LPFN_AcquireDeveloperLicense acquire_license = (LPFN_AcquireDeveloperLicense) GetProcAddress(hDll, "AcquireDeveloperLicense");
    if (acquire_license)
    {
        FILETIME Expiration = {};
        HWND hwnd = GetConsoleWindow();
        HRESULT result = acquire_license(hwnd, &Expiration);
        ...
    }
    ...
    FreeLibrary(hDll);
}

【讨论】:

    【解决方案2】:

    您需要提供一个指向您希望函数在其中存储结果的变量的指针,而不是传递NULL。正如AcquireDeveloperLicense 所指出的,pExpiration 不是可选的 out 参数,这意味着 NULL 不是有效值。

    FILETIME expiration{};
    HWND hwnd = GetConsoleWindow();
    HRESULT result = acquire_license(hwnd, &expiration);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-18
      • 1970-01-01
      • 2011-11-06
      • 2015-04-09
      • 2014-09-19
      • 1970-01-01
      • 2021-01-21
      • 2010-10-04
      相关资源
      最近更新 更多