[英]c++ loadlibrary - import dll
could you please tell me what is wrong with this c++ code?你能告诉我这个 C++ 代码有什么问题吗? it always returns E_INVALIDARG
它总是返回 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);
You are passing a NULL pointer in the 2nd parameter of AcquireDeveloperLicense()
.您正在
AcquireDeveloperLicense()
的第二个参数中传递一个 NULL 指针。 It expects you to pass in a pointer to a FILETIME
struct to receive the license's expiration date.它希望您传入一个指向
FILETIME
结构的指针以接收许可证的到期日期。 The FILETIME
is not optional. FILETIME
不是可选的。
Try this instead:试试这个:
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);
}
You need to provide a pointer to a variable in which you want the function to store the result, not pass NULL
.您需要提供一个指向您希望函数存储结果的变量的指针,而不是传递
NULL
。 As the AcquireDeveloperLicense
notes pExpiration
is an not optional out parameter and that meas that NULL
is not a valid value.正如
AcquireDeveloperLicense
指出的, pExpiration
不是可选的输出参数,这意味着NULL
不是有效值。
FILETIME expiration{};
HWND hwnd = GetConsoleWindow();
HRESULT result = acquire_license(hwnd, &expiration);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.