В учебных материалах есть примеры на си++ и дельфи lesson1(через guardent.exe). Преобразуем в SIGN, сохраняем коды записи в виде кода на си++ .Запускаем код он отрабатывает. Выдает сообщение "Dongle image has been successfully written to the dongle". Пытаемся создать цикл чтения. Отключаем ::GrdInit(hGrd)заменяем цикл записи на цикл чтения:
Валит ошибку 46 (привожу код):
#define CryptPU ЧЧЧЧЧЧЧ // Random value for access codes security
#define CryptRD ЧЧЧЧЧЧЧ // Random value for access codes security
#define CryptWR ЧЧЧЧЧЧЧ // Random value for access codes security
#define CryptMS ЧЧЧЧЧЧЧ // Random value for access codes securit
#include <stdio.h>
#include <conio.h>
#include "grdapi_copy.h" //сделана копия "grdapi.h"
#include <iostream>
#include <string>
#pragma comment(lib, "Grdapi32.lib")
const unsigned char g_byDongleImage[] = {\
0x05, 0x01, 0x09, 0x00, 0x4D, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, \
0xB6, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, \
0x00, 0x00, 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0xD8, 0x08, 0x00, 0x00, \
0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x09, 0x30, 0x60, 0x18, \
0x00, 0x00, 0x00, 0x00, 0x95, 0x71, 0x98, 0x57, \
0x08, 0x1E, 0x4B, 0x32, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, \
0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x57, 0x6F, 0x72, \
0x64, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
const unsigned char g_read_byDongleImage[] = {\
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int main(int argc, char* argv[])
{
DWORD pInfoData;
pInfoData=0;
DWORD* IP_D=&pInfoData;
int nLastError = ::GrdStartup(GrdFMR_Local);
if(nLastError == GrdE_OK)
{
HANDLE hGrd = ::GrdCreateHandle(NULL, GrdCHM_MultiThread, NULL);
int ErrorHandling(HANDLE hGrd,int nLastError);
if(hGrd)
{
//int ErrorHandling(HANDLE hGrd,int nLastError);
if(::GrdSetFindMode(hGrd, GrdFMR_Local, 0, 0, 0, 0, 0, 0, 0, GrdFMM_Sign, GrdFMI_USB) == GrdE_OK)
{
int nRet=::GrdFind(hGrd,GrdF_First,IP_D, NULL);
if(nRet==GrdE_OK)
{
std::cout<<"Dongle has found successfully!"<<"Grd_My_ID="<<*IP_D <<std::endl;
};
if(::GrdSetAccessCodes(hGrd, CryptPU, CryptRD, CryptWR, CryptMS) == GrdE_OK)
{
if(::GrdLogin(hGrd, (DWORD)-1, GrdLM_PerStation) == GrdE_OK)
{
if(::GrdInit(hGrd) == GrdE_OK)
{
if(::GrdWrite(hGrd, GrdUAM_bNProg, sizeof(g_byDongleImage), (void*)g_byDongleImage, NULL) == GrdE_OK)
{
if(::GrdProtect(hGrd, 151, 151, 1, 0, 0, NULL) == GrdE_OK)
{
std::cout<<"Dongle image has been successfully written to the dongle"<<std::endl;
}
}
}
}
}
}
nLastError = GrdGetLastError(hGrd, NULL);
}else
{
nLastError = GrdE_InvalidHandle;
}
::GrdCleanup();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int R_error;
nLastError = ::GrdStartup(GrdFMR_Local);
if(nLastError == GrdE_OK)
{
HANDLE hGrd = ::GrdCreateHandle(NULL, GrdCHM_MultiThread, NULL);
if(hGrd)
{
if(::GrdSetFindMode(hGrd, GrdFMR_Local, 0, 0, 0, 0, 0, 0, 0, GrdFMM_Sign, GrdFMI_USB) == GrdE_OK)
{
int nRet=::GrdFind(hGrd,GrdF_First,IP_D, NULL);
if(nRet==GrdE_OK)
{
std::cout<<"Dongle has found successfully!"<<"Grd_My_ID="<<*IP_D <<std::endl;
};
if(::GrdSetAccessCodes(hGrd, CryptPU, CryptRD, CryptWR, CryptMS) == GrdE_OK)
{
if(::GrdLogin(hGrd, (DWORD)-1, GrdLM_PerStation) == GrdE_OK)
{
R_error=::GrdPI_Activate(hGrd,0,408956937);
if(R_error==GrdE_OK)
{
std::cout<<"GrdInit not used"<<std::endl;
R_error=::GrdPI_Read(hGrd,0,0,32, (void*)g_read_byDongleImage, 1469608341,NULL);
//int ErrorHandling(HANDLE hGrd,int R_error);
//R_error=0;
if(R_error == GrdE_OK)
{
for (int i=0;i<=32;i++){std::cout<<"g_read_byDongleImage["<<i<<"]---"<<g_read_byDongleImage i <<std::endl;};//цикл по i -32 байта тег не дает показать i элемент квадратные скобки убрал
if(::GrdProtect(hGrd, 151, 151, 1, 0, 0, NULL) == GrdE_OK)
{
std::cout<<"Dongle image has been successfully read."<<std::endl;
}
}else{std::cout<<"Dongle error read--"<<R_error<<std::endl;};
}else{std::cout<<"GrdPI unActivate error "<<R_error<<std::endl;
}
}
}
}
nLastError = GrdGetLastError(hGrd, NULL);
}else
{
nLastError = GrdE_InvalidHandle;
}
::GrdCleanup();
}