新增U盘获取图语License功能
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
// LicenseGenerate.cpp
|
||||
#include "LicenseGenerate.h"
|
||||
|
||||
#define PIX_HARDWARE_INFO_BYTES 32
|
||||
#define PIX_LICENCE_BYTES 128
|
||||
|
||||
//const char* pix_license_generate_version();
|
||||
//int pix_license_generate(const unsigned char* hardware_info_ptr, int hardware_info_bytes,
|
||||
// unsigned char* license_ptr, int license_bytes);
|
||||
|
||||
|
||||
typedef const char* (*pix_license_generate_version_func)();
|
||||
typedef int (*pix_license_generate_func)(const unsigned char*, int, unsigned char*, int);
|
||||
|
||||
|
||||
void licenseGenerate()
|
||||
{
|
||||
unsigned char hardware_info[PIX_HARDWARE_INFO_BYTES] = { };
|
||||
unsigned char license_info[PIX_LICENCE_BYTES] = { 0 };
|
||||
|
||||
// 获取并打印当前工作目录
|
||||
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()); // 使用 LoadLibraryW 加载宽字符路径
|
||||
if (hDLL == NULL) {
|
||||
std::cerr << "Failed to load DLL. Error code: " << GetLastError() << std::endl;
|
||||
FreeLibrary(hDLL);
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
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);
|
||||
}
|
||||
else {
|
||||
printf("License is\n");
|
||||
for (int j = 0; j < PIX_LICENCE_BYTES; ++j) {
|
||||
printf("0x%02x, ", license_info[j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
// 释放 DLL
|
||||
FreeLibrary(hDLL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user