63 lines
2.1 KiB
C++
63 lines
2.1 KiB
C++
// LicenseGenerate.cpp
|
|
#include "LicenseGenerate.h"
|
|
|
|
typedef const char* (*pix_license_generate_version_func)();
|
|
typedef int (*pix_license_generate_func)(const unsigned char*, int, unsigned char*, int);
|
|
|
|
bool licenseGenerate(const unsigned char* hardware_info, unsigned char* license_info)
|
|
{
|
|
// 获取当前路径
|
|
wchar_t currentPath[MAX_PATH];
|
|
GetCurrentDirectoryW(MAX_PATH, currentPath);
|
|
std::wcout << L"Current Directory: " << currentPath << std::endl;
|
|
|
|
// 打印 DLL 的完整路径
|
|
std::wstring dllPath = std::wstring(currentPath) + L"\\ThirdParty\\LicenseGenerate\\pix_license.dll";
|
|
std::wcout << L"DLL Path: " << dllPath << std::endl;
|
|
|
|
// 加载 DLL 文件
|
|
HINSTANCE hDLL = LoadLibraryW(dllPath.c_str());
|
|
if (hDLL == NULL) {
|
|
std::cerr << "Failed to load DLL. Error code: " << GetLastError() << std::endl;
|
|
return false;
|
|
}
|
|
pix_license_generate_version_func pix_license_generate_version =
|
|
(pix_license_generate_version_func)GetProcAddress(hDLL, "pix_license_generate_version");
|
|
pix_license_generate_func pix_license_generate =
|
|
(pix_license_generate_func)GetProcAddress(hDLL, "pix_license_generate");
|
|
if (pix_license_generate_version == NULL || pix_license_generate == NULL) {
|
|
std::cerr << "Failed to find one or more functions." << std::endl;
|
|
FreeLibrary(hDLL);
|
|
return false;
|
|
}
|
|
printf("pix_license_generate_version is %s\n",
|
|
pix_license_generate_version());
|
|
|
|
printf("Hardware info:");
|
|
for (int j = 0; j < PIX_HARDWARE_INFO_BYTES; ++j) {
|
|
//hardware_info[j] = j;
|
|
printf("0x%02x, ", hardware_info[j]);
|
|
}
|
|
printf("\n");
|
|
// return 限制不调用 pix_license_generate, 防止减少license个数
|
|
//return false;
|
|
int ret = pix_license_generate(hardware_info, PIX_HARDWARE_INFO_BYTES,
|
|
license_info, PIX_LICENCE_BYTES);
|
|
if (ret != SDK_CODE_OK) {
|
|
printf("Fail to generate license with %d\n", ret);
|
|
FreeLibrary(hDLL);
|
|
return false;
|
|
}
|
|
else {
|
|
printf("License is\n");
|
|
for (int j = 0; j < PIX_LICENCE_BYTES; ++j) {
|
|
printf("0x%02x, ", license_info[j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
FreeLibrary(hDLL);
|
|
return true;
|
|
}
|
|
|