c and delphi高手 (急)(100分)

  • 主题发起人 主题发起人 wrf
  • 开始时间 开始时间
W

wrf

Unregistered / Unconfirmed
GUEST, unregistred user!
c下有如下的声明,请帮我把他们转换成delphi 的格式
typedef struct INITTBL {
long speed
long length
long parity
long sbit
long ptout
long ctout
long cretry
long stopkey1
long stopkey2
} inittbl
int hst_open(long chno, INITTBL *inittbl)
VB的动态库声明方式
Public Declare Function hst_open Lib "hostcm32.dll" (ByVal chno As Long, initab As INITTBL) As Integer

需要转换成delphi的函数声明方式及数据结构
 
type
INITTBL = record
speed : LongInt;
length : LongInt;
parity : LongInt;
sbit : LongInt;
ptout : LongInt;
ctout : LongInt;
cretry : LongInt;
stopkey1: LongInt;
stopkey2: LongInt;
end;

function hst_open(chno: LongInt; var _inittbl: INITTBL): Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
implementation
function hst_open; external [red]'DLL文件名'[/red];
end.
 
tseug你说的对,再请您帮把以下的的转换一下,成功后就给你加分了
Public Declare Function hst_idtblclr Lib "hostcm32.dll" () As Integer
Public Declare Function hst_idtbladd Lib "hostcm32.dll" (ByVal iddata As String) As Integer
Public Declare Function hst_open Lib "hostcm32.dll" (ByVal chno As Long, initab As INITTBL) As Integer
Public Declare Function hst_close Lib "hostcm32.dll" () As Integer
Public Declare Function hst_polling Lib "hostcm32.dll" (recno As Long, ByVal ioboxno As Long) As Integer
Public Declare Function hst_idtblgetidno Lib "hostcm32.dll" () As Integer
Public Declare Function hst_getcinffirst Lib "hostcm32.dll" (inftab As CINFTBL) As Integer
Public Declare Function hst_getcinfnext Lib "hostcm32.dll" (inftab As CINFTBL) As Integer
Public Declare Function hst_filerecv Lib "hostcm32.dll" (ByVal pname As String, inftab As CINFTBL) As Integer
Public Declare Function hst_filesend Lib "hostcm32.dll" (ByVal pname As String, inftab As CINFTBL) As Integer
Public Declare Function hst_disconnect Lib "hostcm32.dll" (ByVal mode As Long, inftab As CINFTBL) As Integer
Public Declare Function hst_idtblgetid Lib "hostcm32.dll" (ByVal recno As Long, ByVal iddata As String) As Integer
 
int hst_polling(long *recno, long ioboxno)
int hst_filerecv(UCHAR *pname, CINFTBL *cinftbl)
 
long -> Integer
 
devuser你的办法不行,我已经试过了,报错或执行的结果不对
 
CINFTBL 未知, 剩下的改好了.


function hst_open(chno: LongInt; var _inittbl: INITTBL): Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function hst_idtblclr : Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function hst_idtbladd(iddata : string) :Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF} ;
function hst_open(chno : LongInt, var _initab : INITTBL) : Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function hst_close : Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function hst_polling (recno : LongInt, ioboxno : LongInt) : Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function hst_idtblgetidno : Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function hst_getcinffirst(var inftab : CINTFTBL): Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function hst_getcinfnext(var inftab : CINFTBL) : Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function hst_filerecv(pname : String, var inftab : CINFTBL) : Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function hst_filesend(pname : String, var inftab : CINFTBL) : Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function hst_disconnect(mode : LongInt, var inftab : CINFTBL) : Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function hst_idtblgetid(recno : LongInt, iddata : String) : Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};

implementation

function hst_open; external 'hostcm32.dll';
function hst_idtblclr;external 'hostcm32.dll';
function hst_idtbladd;external 'hostcm32.dll';
function hst_open;external 'hostcm32.dll';
function hst_close;external 'hostcm32.dll';
function hst_polling;external 'hostcm32.dll';
function hst_idtblgetidno;external 'hostcm32.dll';
function hst_getcinffirst;external 'hostcm32.dll';
function hst_getcinfnext;external 'hostcm32.dll';
function hst_filerecv;external 'hostcm32.dll';
function hst_filesend;external 'hostcm32.dll';
function hst_disconnect;external 'hostcm32.dll';
function hst_idtblgetid;external 'hostcm32.dll';

 
tseug 按你的方法,执行hst_polling 会报错
按以下写会执行,但不会报错,但是执行的结果不对,同样在vb 下成功执行,可是在d下返回
的值不对,不能继续执行下去
FUNCTION hst_polling(var recno: integer; ioboxno: integer): integer; stdcall; external 'hostcm32.dll';
另外这是在dt900下的通讯函数!您是否有这方面的经验!
int hst_polling(long *recno, long ioboxno)
int hst_filerecv(UCHAR *pname, CINFTBL *cinftbl)
 
增加类型声明如下:
type pINITTBL=^INITTBL;
type INITTBL=.....
function hst_open(chno: LongInt;_inittbl: pINITTBL): Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
..
搞定
 
windcolor,类型定义应该没有问题,是在hst_polling(long *recno, long ioboxno)
出问题
 
你把dll文件发给我, tseug@263.net, 还有, 让我看看错误信息
 
>Public Declare Function hst_polling Lib "hostcm32.dll" (recno As Long, ByVal ioboxno As Long) As Integer
>hst_polling(long *recno, long ioboxno)

参考你的两段代码, 你把声明换成下面的看看
function hst_polling (var recno : LongInt, ioboxno : LongInt) : Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
^^^^^^^^^^^^
 
Function hst_polling(reco :pchar;iobox:longint):integer;stdcall external 'hostcm32.dll'
reco 跟PCHAR 的转换 可以这样

var
a:integer;
reco :=pchar(a);

再不行,,就把STDCALL 换成 CDECL 然后就再没有出错的理由了
 
多人接受答案了。
 
靠,好久没来了,错过了
给你个网站:www.drbob.后面的积不起来了可能是com
这个还专门有个软件来翻译的,不过是E问了[:)]
 
后退
顶部