导航:
论坛 -> DELPHI技术
斑竹:liumazi,sephil
作者:
2017/2/15 21:37:15
标题:
DLL声明里的创建实例对象要如何转delphi?
浏览:2014
加入我的收藏
楼主:
这是头文件里的内容,请问需要如何才能转成delhi的,谢谢。 typedef struct FactorySDKDll BL_FactorySDKDll; __declspec(dllexport) BL_FactorySDKDll *BL_createInstance(); __declspec(dllexport) bool BL_releaseInstance(BL_FactorySDKDll* inst); //说明:c) 结构体BL_FactorySDKDll只是一个标志,用于创建DLL实例对象,外部调用不需关心其内容。
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/16 8:14:27
1楼:
不同语言之间传递实例是不现实的。
----------------------------------------------
Delphi爱好者。
作者:
2017/2/16 8:57:39
2楼:
FactorySDKDll 没看到具体定义。无法回答。
----------------------------------------------
(C)(P)Flying Wang
作者:
2017/2/16 9:29:29
3楼:
FactorySDKDll 应该只是声明了一个对象 大概是这样写的 type TFactorySDKDll = class end; var BL_FactorySDKDll: TFactorySDKDll; 说明: BL_createInstance创建DLL实例,用于后续调用DLL接口时传入该实例
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/16 9:48:56
4楼:
那就没辙了。 DLL 只支持 基本类型和 结构体,不支持类。
----------------------------------------------
(C)(P)Flying Wang
作者:
2017/2/16 10:02:36
5楼:
但是提供DLL的客户说,他的DLL已经可以被其他语言调用的,比如java
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/16 10:13:41
6楼:
他的 TFactorySDKDll 到底如何定义的,你还是不说。无法帮你。
----------------------------------------------
(C)(P)Flying Wang
作者:
2017/2/16 11:02:40
7楼:
typedef struct FactorySDKDll BL_FactorySDKDll; 这个明显就是一个结构. 怎么会翻译成class的?
----------------------------------------------
--
作者:
2017/2/16 11:59:14
8楼:
给出个c语言结构体出来。这边会有人帮你转成pascal的。 java 也是根据c结构体转的
----------------------------------------------
-
作者:
2017/2/16 12:30:13
9楼:
楼主是保密局的,肯定不能告诉大家真相的。
----------------------------------------------
(C)(P)Flying Wang
作者:
2017/2/16 13:31:23
10楼:
我又不傻,本来就是求帮助,干嘛保密,真的关于FactorySDKDll就只有这么几句话 下面是头文件的所有内容 #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); __declspec(dllexport) bool BL_startJLINK(BL_FactorySDKDll* inst, char* mac, BL_JLinkProcessCB cb, BL_JLinkScheduleCB scheduleCb, void* object = NULL); } #endif // SDKDLLINTERFACE_H
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/16 14:42:31
11楼:
想直接在不通语言间导出类是不可能的。 纯虚类是可以的。
----------------------------------------------
-
作者:
2017/2/16 14:59:50
11楼:
找到一个文件不知道有么有用 #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;
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/16 15:07:38
12楼:
那如果就是纯虚类,要如何操作?
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/16 15:28:40
13楼:
客户说“typedef struct FactorySDKDll BL_FactorySDKDll;这是一个假的定义,其实void*,用的时候当作一个类好了,通过creat函数,创建出来复制给这个对象。每一个对象代表一个实例(线程),每次调用dll中的其他函数的时候,传入不同的实例。”
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/16 15:54:47
14楼:
看了 typedef struct 的介绍。 FactorySDKDll 是 结构体的名字 BL_FactorySDKDll 是 类型名称。 BL_FactorySDKDll 是 FactorySDKDll 结构体的 类型名。 那么 FactorySDKDll 就是一个简单的结构体,不是类,你的客户骗你呢。
----------------------------------------------
(C)(P)Flying Wang
作者:
2017/2/16 16:00:06
15楼:
type TBL_FactorySDKDll = record end; PBL_FactorySDKDll = ^TBL_FactorySDKDll; __declspec(dllexport) BL_FactorySDKDll *BL_createInstance(); 翻译: function BL_createInstance(): PBL_FactorySDKDll; 可能是 stdcall; external '你的dll文件名'; __declspec(dllexport) bool BL_releaseInstance(BL_FactorySDKDll* inst); 翻译: function BL_releaseInstance(inst: PBL_FactorySDKDll): BOOL; 可能是 stdcall; external '你的dll文件名';
----------------------------------------------
(C)(P)Flying Wang
作者:
2017/2/16 16:04:36
16楼:
觉得就是把个空结构体当指针用了。
----------------------------------------------
-
作者:
2017/2/16 20:46:24
17楼:
非常感谢 wang_80919和各位的热心帮助 , 如果这是个空的结构体,那调用 BL_createInstance(),怎么调用啊? var BL_FactorySDKDll :TBL_FactorySDKDll begin // end;
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/16 20:54:43
18楼:
不是说了是结构么。。。 type PBL_FactorySDKDll = ^TBL_FactorySDKDll; TBL_FactorySDKDll = record end; funciton BL_createInstance(): PBL_FactorySDKDll; cdecl; external ''; ... 调用: var pRet: PBL_FactorySDKDll; begin pRet := BL_createInstance(); ... end;
----------------------------------------------
--
作者:
2017/2/16 21:06:46
19楼:
用.h转pas工具
----------------------------------------------
相信自己,若自己都不相信,那还有谁可信。
作者:
2017/2/16 21:39:28
20楼:
我先把这个SDK包传上来。 http://pan.baidu.com/s/1boE1D87
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/17 10:11:56
21楼:
是的,pRet := BL_createInstance();是不会出错的,但是接着运行 TF:=BL_setPackage(pRet,'E:\7681passthrough\'); 就会出错,难道还是前面定义错了? 这个是这个E:\7681passthrough\的文件夹 http://pan.baidu.com/s/1dEM5izJ
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/17 11:13:39
22楼:
BL_setPackage 你 PASCAL 是如何定义的?
----------------------------------------------
(C)(P)Flying Wang
作者:
2017/2/17 11:36:37
23楼:
function BL_setPackage(inst:PBL_FactorySDKDll;packDir:PChar): Boolean; stdcall; external BL_DLL; 这样正确吗?
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/17 12:12:52
24楼:
PAnsiChar 或 PWideChar 请指定一种。 内容要 #0 结尾。 var A: PAnsiChar; W: PWideChar; U: PUTF8Char; begin A := Addr(TEncoding.ANSI.GetBytes('你的字符串' + #0)[0]); W := Addr(TEncoding.Unicode.GetBytes('你的字符串' + #0)[0]); U := Addr(TEncoding.UTF8.GetBytes('你的字符串' + #0)[0]); end;
----------------------------------------------
(C)(P)Flying Wang
作者:
2017/2/17 13:16:49
25楼:
话说 wang_80919 你的这个不是在回复我这个帖子吧
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/17 14:18:50
26楼:
您就当我吃多了撑着乱回帖吧。 爱信不信,关我屁事。
----------------------------------------------
(C)(P)Flying Wang
作者:
2017/2/17 14:20:38
26楼:
我用的是D7,TEncoding用不了啊
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/17 14:22:09
27楼:
wang_80919 ,我一开始没明白你帖子里的内容,现在知道了,你的意思是 var TF:Boolean; P:PAnsiChar; begin P:=Addr(TEncoding.ANSI.GetBytes('E:\7681passthrough' + #0)[0]); TF:=BL_setPackage(pRet,P); 是吧?
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/18 12:20:59
28楼:
直接的字符串常量不用你去手动用#0结尾. 兰州就不注意看看我的定义和你自己的定义有什么不同的么?
----------------------------------------------
--
作者:
2017/2/18 16:28:18
29楼:
bahamut8348 是对的,,“cdecl”
----------------------------------------------
只会简单使用,并未精通深入
作者:
2017/2/20 8:33:31
30楼:
也许楼上正解。 虽然 WIN 系统 用 stdcall 的多一些。但是 楼主的 C 代码,好像写了 decl 开头的定义。 也许这是 cdecl 的意思吧。
----------------------------------------------
(C)(P)Flying Wang