16,748
社区成员
发帖
与我相关
我的任务
分享
//声明部分
const
BLSDK ='FactorySDKDll.dll';
STEP_DESC_SIZE=100;
type
TBL_FactorySDKDll = record
end;
PBL_FactorySDKDll = ^TBL_FactorySDKDll;
TBL_StepInfo = record
step:Integer;
desc:array [0..STEP_DESC_SIZE-1] of Char;
totalStep:Integer;
end;
PBL_StepInfo = ^TBL_StepInfo;
BL_ModuleType=(BL_ModuleCommon,BL_Module433Device,BL_ModuleJLink,BL_ModuleUndefined);
TBL_PackageInfo = record
isOK:Boolean;
moduleType:BL_ModuleType;
totalSteps:Integer;
end;
PBL_PackageInfo = ^TBL_PackageInfo;
function BL_getSDKVersion(): PChar; cdecl; external BLSDK; //pass
function BL_createInstance(): PBL_FactorySDKDll; cdecl; external BLSDK; //pass
function BL_releaseInstance(inst:PBL_FactorySDKDll): Boolean; cdecl; external BLSDK;
function BL_setPackage(inst:PBL_FactorySDKDll;packDir:PChar): Boolean; cdecl; external BLSDK; //pass
function BL_setPackageAndGetInfo(inst:PBL_FactorySDKDll;packDir:PChar):TBL_PackageInfo; cdecl; external BLSDK;
function BL_getTotalSteps(inst:PBL_FactorySDKDll):PBL_StepInfo; cdecl; external BLSDK;
function BL_getTotalStepsCount(inst:PBL_FactorySDKDll):Integer; cdecl; external BLSDK; //pass
function BL_getStepInfo(inst:PBL_FactorySDKDll;step:Integer):PChar; cdecl; external BLSDK;
//调用部分,根据流程
var
pRet: PBL_FactorySDKDll;//全局变量
//创建对象并设置固件包,packDir是路径
procedure TForm1.btnBL_setPackageClick(Sender: TObject);
var
PathStr:PChar;
begin
Memo1.Clear;
//创建DLL实例
pRet:=BL_createInstance();
PathStr:=PChar(Edit1.Text);
//设置固件包
if BL_setPackage(pRet,PathStr) then
Memo1.Lines.Add('BL_setPackage:true')
else
Memo1.Lines.Add('BL_setPackage:false');
end;
//这个函数运行结束后错误
procedure TForm1.btnBL_setPackageAndGetInfoClick(Sender: TObject);
var
BL_PackageInfo:TBL_PackageInfo;
i:Integer;
PathStr:PChar;
ModuleType:string;
begin
//返回值正确,但是函数执行完毕报内存错误
pRet:=BL_createInstance();
PathStr:=PChar(Edit1.Text);
BL_PackageInfo:=BL_setPackageAndGetInfo(pRet,PathStr);
if BL_PackageInfo.isOK then
Memo1.Lines.Add('isOK:true')
else
Memo1.Lines.Add('isOK:false');
ModuleType:=GetEnumName(TypeInfo(BL_ModuleType),Ord(BL_PackageInfo.moduleType));
Memo1.Lines.Add(ModuleType);
Memo1.Lines.Add(IntToStr(BL_PackageInfo.totalSteps));
end;
//这个释放对象,直接卡死
procedure TForm1.btnBL_releaseInstanceClick(Sender: TObject);
begin
if BL_releaseInstance(pRet) then
Memo1.Lines.Add('BL_releaseInstance:true')
else
Memo1.Lines.Add('BL_releaseInstance:false');
end;
//返回值乱码
procedure TForm1.btnBL_getStepInfoClick(Sender: TObject);
var
S:string;
P:PChar;
begin
P:=BL_getStepInfo(pRet,0);
Memo1.Lines.Add(P);
{乱码内容为:皢 铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪~?,F^}
end;
//也是乱码
procedure TForm1.btnBL_getTotalStepsClick(Sender: TObject);
var
XBL_StepInfo:PBL_StepInfo;
i,:Integer;
begin
XBL_StepInfo:=BL_getTotalSteps(pRet) ;
for i := 0 to 20 do //
begin
Memo1.Lines.Add(XBL_StepInfo^.desc);
inc(XBL_StepInfo);
end;
{乱码内容:
杩涘叆recovery
鐑у綍mac
妫€娴媘ac涓€鑷存€?
鍗囩骇udp鍥轰欢
鍐嶆鎵爜
铪铪
铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪铪}
end;
type
TBL_FactorySDKDll = record
end;
PBL_FactorySDKDll = ^TBL_FactorySDKDll;
function BL_createInstance(): PBL_FactorySDKDll; stdcall; external BL_DLL;
function BL_setPackage(inst:PBL_FactorySDKDll;packDir:PChar): Boolean; stdcall; external BL_DLL;
调用
var
pRet: PBL_FactorySDKDll;
//第一步创建
procedure TForm1.btn2Click(Sender: TObject);
begin
pRet:=BL_createInstance();
Edit1.Text := Format('%p', [ @pRet]);//看看是否为空
end;
//第二步,这里出错
procedure TForm1.btn3Click(Sender: TObject);
var
TF:Boolean;
begin
TF:=BL_setPackage(pRet,'E:\\7681passthrough');
end;
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QDebug>
#include <QLibrary>
#include "sdkdllinterface.h"
#include <QFile>
#include <QDir>
namespace Ui {
class MainWindow;
}
typedef BL_FactorySDKDll* (*CreateDLLFunc)();
typedef bool (*DeleteDllFunc)(BL_FactorySDKDll*);
typedef bool (*SetPackageFunc)(BL_FactorySDKDll*, char*);
typedef bool (*SetDidLicenseFunc)(BL_FactorySDKDll*, char*, int, char*, int);
typedef BL_StepInfo* (*GetTotalStepFunc)(BL_FactorySDKDll*);
typedef bool (*RegisterCBFunc)(BL_FactorySDKDll*, BL_ProcessCB, void*);
typedef bool (*ExecuteStepFunc)(BL_FactorySDKDll*, int);
typedef bool (*OpenPortFunc)(BL_FactorySDKDll*, BL_SerialPortInfo, BL_OpenPortCB, void*);
typedef bool (*ClosePortFunc)(BL_FactorySDKDll*);
void callBack(int step, bool ret, char* desc, char* errMsg, int errCode, char* portData, void* object);
void openPortResult(bool isOK, void* object);
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void initFunction();
void showMessage(int step, bool ret, char* desc, char* errMsg, int errCode, char* portData);
private slots:
void on_btnCreate_clicked();
void on_btnSetPack_clicked();
void on_btnSetLicense_clicked();
void on_btnGetSteps_clicked();
void on_btnRegister_clicked();
void on_btnOpen_clicked();
void on_btnExecute_clicked();
void on_btnClose_clicked();
void on_btnRelease_clicked();
private:
Ui::MainWindow *ui;
CreateDLLFunc createFunc;
DeleteDllFunc deleteFunc;
SetPackageFunc setPackFunc;
SetDidLicenseFunc setLicenseFunc;
GetTotalStepFunc totalStepFunc;
RegisterCBFunc registerCBFunc;
ExecuteStepFunc executeFunc;
OpenPortFunc openFunc;
ClosePortFunc closeFunc;
BL_FactorySDKDll *dll;
#ifndef SDKDLLINTERFACE_H
#define SDKDLLINTERFACE_H
#include <cstddef>
#define STEP_DESC_SIZE 100
typedef struct BL_SerialPortInfo
{
char portName[100];
int baduRate;
int dataBit;
int parity;
int stopBit;
} BL_SerialPortInfo;
typedef struct BL_StepInfo
{
int step;
char desc[STEP_DESC_SIZE];
int totalStep;
}BL_StepInfo;
enum BL_ModuleType {
BL_ModuleCommon,
BL_Module433Device,
BL_ModuleJLink,
BL_ModuleUndefined
};
typedef struct BL_PackageInfo
{
bool isOK;
BL_ModuleType moduleType;
bool isNeedLicense;
int totalSteps;
}BL_PackageInfo;
typedef void (*BL_ProcessCB) (int currentStep, bool result, char* stepDesc,
char* errMsg, int errCode, char* portData, void* object);
typedef void (*BL_OpenPortCB)(bool result, void* object);
typedef void (*BL_JLinkProcessCB)(int currentStep, int totalStep, bool result, char* msg, void* object);
typedef void (*BL_JLinkScheduleCB)(int value, void* object);
typedef struct FactorySDKDll BL_FactorySDKDll;
extern "C" {
__declspec(dllexport) const char* BL_getSDKVersion();
__declspec(dllexport) BL_FactorySDKDll *BL_createInstance();
__declspec(dllexport) bool BL_releaseInstance(BL_FactorySDKDll* inst);
__declspec(dllexport) bool BL_setPackage(BL_FactorySDKDll* inst, char* packDir);
__declspec(dllexport) BL_PackageInfo BL_setPackageAndGetInfo(BL_FactorySDKDll* inst, char* packDir);
__declspec(dllexport) bool BL_isNeedLicense(BL_FactorySDKDll* inst);
__declspec(dllexport) char* BL_makeLicense(BL_FactorySDKDll* inst, char* did, char* license, char* facPubKey, char* dsig);
__declspec(dllexport) bool BL_setDidLicense(BL_FactorySDKDll* inst, char* did, int didSize,
char* license, int licenseSize);
__declspec(dllexport) BL_StepInfo* BL_getTotalSteps(BL_FactorySDKDll* inst);
__declspec(dllexport) int BL_getTotalStepsCount(BL_FactorySDKDll* inst);
__declspec(dllexport) char* BL_getStepInfo(BL_FactorySDKDll* inst, int step);
__declspec(dllexport) bool BL_registerCallback(BL_FactorySDKDll* inst, BL_ProcessCB cb, void* object = NULL);
__declspec(dllexport) bool BL_executeStep(BL_FactorySDKDll* inst, int step);
__declspec(dllexport) bool BL_openSerialPort(BL_FactorySDKDll* inst, BL_SerialPortInfo info, BL_OpenPortCB cb, void* object = NULL);
__declspec(dllexport) bool BL_closeSerialPort(BL_FactorySDKDll* inst);
__declspec(dllexport) char* BL_getLastError(BL_FactorySDKDll* inst);
__declspec(dllexport) bool BL_setLastScanDid(BL_FactorySDKDll* inst, char* did, int didSize);
__declspec(dllexport) BL_ModuleType BL_getModuleType(BL_FactorySDKDll* inst); //12.16新增
__declspec(dllexport) bool BL_startJLINK(BL_FactorySDKDll* inst, char* mac, BL_JLinkProcessCB cb,
BL_JLinkScheduleCB scheduleCb, void* object = NULL); //12.16新增
}
#endif // SDKDLLINTERFACE_H