最后一段, BCB 转Delphi ( 积分: 200 )

  • 主题发起人 主题发起人 BBM
  • 开始时间 开始时间
B

BBM

Unregistered / Unconfirmed
GUEST, unregistred user!
////////////////////////////////////////////////////////////////////////////
class TDllCall : public TObject
{
// Construction
public:
__fastcall TDllCall::TDllCall();
__fastcall TDllCall::~TDllCall();

// Attributes
public:
HINSTANCE hLibrary;
TMemoryStream *m_File;
void* m_pDevice;
void* m_pActReturn;
int nSizeOfData;
BOOL bGetData;
int nInfoReturn;
int nTagAdr, nMyAdr;
BOOL bConnect, bDisConnect;
int nFileHandle;
int nFileHandle1;

// Operations
public:
BOOL __fastcall LoadFunction();
String __fastcall ShowMessage(int nMessage, int nFontMsg);
String __fastcall AddZero(String strData, int nLength);
int __fastcall myatoi(char chChar);
String __fastcall Learch(const String& strSrc, char chChar);
String __fastcall HexToStr(int n);
void __fastcall WriteFile(int nAdr, int nInfoReturn, int nHandle,
String strSectorNum, String strOldAKey, String strOldBKey,
String strNewAKey, String strNewBKey);
String __fastcall AddAttGuardRecord(int nCount, ATTGUARDRECORD CardRecord);
String __fastcall AddPOSRecord(int nCount, POSRECORD CardRecord);
int __fastcall WriteAttGuardFile(int nCount, ATTGUARDRECORD CardRecord);
int __fastcall WritePOSFile(int nCount, POSRECORD CardRecord);

typedef void* __stdcall (OPENDEVICE)(int nMyAddress, HWND hWnd);
typedef void __stdcall (RECVEDITION)(LPTSTR lpEdition);
typedef BOOL __stdcall (CONNECT)(void* pDevice, LPCTSTR lpCommDef);
typedef void __stdcall (SETADDLOG)(void* pDevice, BOOL bAddLog);
typedef void __stdcall (SETINNERCODE)(void* pDevice, BOOL bBig5);
typedef void __stdcall (SETINNERCMD)(void* pDevice, BOOL bInner);
typedef void __stdcall (SETCOMMKEY)(void* pDevice, LPCTSTR lpCommKey);
typedef void __stdcall (SETWAITTIME)(void* pDevice, DWORD dwWaitTime);
typedef void* __stdcall (STARTICDMCMD)(void* pDevice, int nAddress, int nCommand,
void* pParameters = NULL, int nSizeOfParameter = 0);
typedef int __stdcall (GETSIZEOFDATA)(void* pCommand);
typedef BOOL __stdcall (GETDATA)(void* pCommand, void* pDataBuffer, int nSize);
typedef int __stdcall (GETCMDRESULT)(void* pCommand);
typedef void __stdcall (ENDICDMCMD)(void* pCommand);
typedef BOOL __stdcall (DISCONNECT)(void* pDevice);
typedef void __stdcall (CLOSEDEVICE)(void* pDevice);
typedef void __stdcall (SETMYADDRESS)(void* pDevice, int nAddress);



typedef void __stdcall (SENDFRAME)(void* pDevice, LPCTSTR lpSendFrm);
typedef void __stdcall (CLEARRECVSTR)(void* pDevice);
typedef BOOL __stdcall (RECVSTREAM)(void* pDevice, LPTSTR lpRecvStr);
typedef BOOL __stdcall (RECVHDLC)(void* pDevice, LPTSTR lpRecvStr);


SENDFRAME* lpSendFrame;
CLEARRECVSTR* lpClearRecvStr;
RECVSTREAM* lpRecvStream;
RECVHDLC* lpRecvHDLC;



OPENDEVICE* lpOpenDevice;
RECVEDITION* lpRecvEdition;
CONNECT* lpConnect;
SETADDLOG* lpSetAddLog;
SETINNERCODE* lpSetInnerCode;
SETINNERCMD* lpSetInnerCmd;
SETWAITTIME* lpSetWaitTime;
SETCOMMKEY* lpSetCommKey;
STARTICDMCMD* lpStartICDMCmd;
GETSIZEOFDATA* lpGetSizeOfData;
GETDATA* lpGetData;
GETCMDRESULT* lpGetCmdResult;
ENDICDMCMD* lpEndICDMCmd;
DISCONNECT* lpDisConnect;
CLOSEDEVICE* lpCloseDevice;
SETMYADDRESS* lpSetMyAddress;

// Generated message map functions
protected:

};
/////////////////////////////////////////////////////////////////////////////
#endif
 
////////////////////////////////////////////////////////////////////////////
class TDllCall : public TObject
{
// Construction
public:
__fastcall TDllCall::TDllCall();
__fastcall TDllCall::~TDllCall();

// Attributes
public:
HINSTANCE hLibrary;
TMemoryStream *m_File;
void* m_pDevice;
void* m_pActReturn;
int nSizeOfData;
BOOL bGetData;
int nInfoReturn;
int nTagAdr, nMyAdr;
BOOL bConnect, bDisConnect;
int nFileHandle;
int nFileHandle1;

// Operations
public:
BOOL __fastcall LoadFunction();
String __fastcall ShowMessage(int nMessage, int nFontMsg);
String __fastcall AddZero(String strData, int nLength);
int __fastcall myatoi(char chChar);
String __fastcall Learch(const String& strSrc, char chChar);
String __fastcall HexToStr(int n);
void __fastcall WriteFile(int nAdr, int nInfoReturn, int nHandle,
String strSectorNum, String strOldAKey, String strOldBKey,
String strNewAKey, String strNewBKey);
String __fastcall AddAttGuardRecord(int nCount, ATTGUARDRECORD CardRecord);
String __fastcall AddPOSRecord(int nCount, POSRECORD CardRecord);
int __fastcall WriteAttGuardFile(int nCount, ATTGUARDRECORD CardRecord);
int __fastcall WritePOSFile(int nCount, POSRECORD CardRecord);

typedef void* __stdcall (OPENDEVICE)(int nMyAddress, HWND hWnd);
typedef void __stdcall (RECVEDITION)(LPTSTR lpEdition);
typedef BOOL __stdcall (CONNECT)(void* pDevice, LPCTSTR lpCommDef);
typedef void __stdcall (SETADDLOG)(void* pDevice, BOOL bAddLog);
typedef void __stdcall (SETINNERCODE)(void* pDevice, BOOL bBig5);
typedef void __stdcall (SETINNERCMD)(void* pDevice, BOOL bInner);
typedef void __stdcall (SETCOMMKEY)(void* pDevice, LPCTSTR lpCommKey);
typedef void __stdcall (SETWAITTIME)(void* pDevice, DWORD dwWaitTime);
typedef void* __stdcall (STARTICDMCMD)(void* pDevice, int nAddress, int nCommand,
void* pParameters = NULL, int nSizeOfParameter = 0);
typedef int __stdcall (GETSIZEOFDATA)(void* pCommand);
typedef BOOL __stdcall (GETDATA)(void* pCommand, void* pDataBuffer, int nSize);
typedef int __stdcall (GETCMDRESULT)(void* pCommand);
typedef void __stdcall (ENDICDMCMD)(void* pCommand);
typedef BOOL __stdcall (DISCONNECT)(void* pDevice);
typedef void __stdcall (CLOSEDEVICE)(void* pDevice);
typedef void __stdcall (SETMYADDRESS)(void* pDevice, int nAddress);



typedef void __stdcall (SENDFRAME)(void* pDevice, LPCTSTR lpSendFrm);
typedef void __stdcall (CLEARRECVSTR)(void* pDevice);
typedef BOOL __stdcall (RECVSTREAM)(void* pDevice, LPTSTR lpRecvStr);
typedef BOOL __stdcall (RECVHDLC)(void* pDevice, LPTSTR lpRecvStr);


SENDFRAME* lpSendFrame;
CLEARRECVSTR* lpClearRecvStr;
RECVSTREAM* lpRecvStream;
RECVHDLC* lpRecvHDLC;



OPENDEVICE* lpOpenDevice;
RECVEDITION* lpRecvEdition;
CONNECT* lpConnect;
SETADDLOG* lpSetAddLog;
SETINNERCODE* lpSetInnerCode;
SETINNERCMD* lpSetInnerCmd;
SETWAITTIME* lpSetWaitTime;
SETCOMMKEY* lpSetCommKey;
STARTICDMCMD* lpStartICDMCmd;
GETSIZEOFDATA* lpGetSizeOfData;
GETDATA* lpGetData;
GETCMDRESULT* lpGetCmdResult;
ENDICDMCMD* lpEndICDMCmd;
DISCONNECT* lpDisConnect;
CLOSEDEVICE* lpCloseDevice;
SETMYADDRESS* lpSetMyAddress;

// Generated message map functions
protected:

};
/////////////////////////////////////////////////////////////////////////////
#endif
 
TDllCall=class(TObject)
public
constructor Create;
Destructor Destroy;override;
hLibrary:THandle;//HINSTANCE
m_File:TMemoryStream;
m_pActReturn:Pointer;
nSizeOfData:Integer;
bGetData:boolean;
nInfoReturn,nTagAdr,nMyAdr:Integer;
bConnect,bDisConnect:boolean;
nFileHandle,nFileHandle1:Integer;

{CB里面SENDFREAME* 是指针的意思,如果下面不行的话,你应该新建一个指针类型
PSENDFRAME=^SENDFRAME}
lpSendFrame:SENDFRAME;
lpClearRecvStr:CLEARRECVSTR;
lpRecvStream:RECVSTREAM;
lpRecvHDLC:RECVHDLC;

lpOpenDevice:OPENDEVICE;
lpRecvEdition:RECVEDITION;
lpConnect:CONNECT;
lpSetAddLog;SETADDLOG;
lpSetInnerCode:SETINNERCODE;
lpSetInnerCmd:SETINNERCMD;
lpSetWaitTime:SETWAITTIME;
lpSetCommKey:SETCOMMKEY;
lpStartICDMCmd:STARTICDMCMD;
lpSetSizeOfData:GETSIZEOFDATA;
lpGetData:GETDATA;
lpGetCmdResult:GETCMDRESULT;
lpEndICDMCmd:ENDICDMCMD;
lpDisConnect:DISCONNECT;
lpCloseDevice:CLOSEDEVICE;

function LoadFunction():boolean;
function ShowMessage(nMessage,nFontmsg:Integer):String;
function AddZero(strData:String;nLength:integer):String;
function myatoi(chChar:Char):Integer;
function Learch(const strSrc:String;chChar):String;
function HexToStr(n:Integer):String;
procedure WriteFile(nAdr,nInfoReturn,nHandle:Integer;strSectorNum,strOldAKey,StrOldOldBKey,strnewAKey,strNewBKey:String);
function AddAttGuardRecord(nCount:Integer;CardRecord:ATTGUARDRECORD):sTRING;
function AddPOSrecord(nCount:Integer;CardRecord:POSRECORD ):String;
function WriteAttGuardFile(nCount:Integer;CardRecord:ATTGUARDRECORD ):Integer;
function WritePOSFile(nCount:Integer;CardRecord:POSRECORD ):integer;

//下面的代码应该是引用DLL的代码,不知道有没有错,很久没有用C了
function OPENDEVICE(nMyAddress;hWnd:THandle):Pointer;stdcall;
procedure RECVEDTION(lpEdition:LPCTSTR);
function CONNECT(pDevice:Pointer;lpCommDef:LPCTSTR):boolean;
procedure SETADDLOG(pDevice:Pointer;bAddLog:boolean);
procedure SETINNERCODE(pDevice;Pointer;bBig5:boolean);
procedure SETINNERCMD(pDevice:Pointer;bInner:boolean);
procedure SETCOMMKEY(pDevice:Pointer;lpCommKey:CPCTSTR);
procedure SETWAITTIME(pDevice:Pointer;dwWaitTime:Word);
function STARTTICDMCMD(pDevice:Pointer;nAddress,,Command:Integer;pParameters:Pointer=nil;nSizeOfParamter:Integer=0):Pointer;
function GETSIZEOFDATA(pCommand:Pointer):Integer;
funcction GETADATA(pCommand,pDataBuffer:Pointer;nSize:Integer):boolean;
function GETCMDRESULT(pCommand:Pointer):Integer;
procedure ENDICDMCMD(pCommand:Pointer);
function DISCONNECT(pDevice:Pointer):boolean;
procedure CLOSEDEVICE(pDevice:Pointer);
procedure SETMYADDRESS(pDevice:Pointer;nAddress:Integer);

procedure SENDFRAME(pDevice:Pointer;lpSendFrm:LPCTSTR);
procedure (CLEARRECVSTR(pDevice:Pointer);
function RECVSTREAM(pDevice:Pointer;lprecvStrL:LPTSTR):boolean;
function RECVHDLC(pDevice:Pointer;lpRecvStr:LPTSTR):boolean;
end;


不知道转的正确不?
你在DLL调用的函数中需要写引用代码的
 
DisabledAll();
Label_ShowRlt->Caption = "";
int nAdr;
m_pDllCall->lpSetWaitTime(m_pDllCall->m_pDevice, 500);
m_pDllCall->m_pActReturn = m_pDllCall->lpStartICDMCmd(m_pDllCall->m_pDevice, m_pDllCall->nTagAdr,
nSearchDM, NULL, 0);
if(m_pDllCall->m_pActReturn != NULL)
{
m_pDllCall->nInfoReturn = m_pDllCall->lpGetCmdResult(m_pDllCall->m_pActReturn);
if(m_pDllCall->nInfoReturn == nRecvSuccess)
{
int nLength = m_pDllCall->lpGetSizeOfData(m_pDllCall->m_pActReturn);
m_pDllCall->lpGetData(m_pDllCall->m_pActReturn, &nAdr, nLength);
}
}
 
上面一小段中的:
int nAdr;

lpGetData(m_pDllCall->m_pActReturn, &nAdr, nLength);
函数是:BOOL lpGetData(void* pCommand, void* pDataBuffer, int nSize)

问题我在delphi中 这个子int nAdr; 怎么用啊? &nAdr 是什么类型?
 
不好意思,我看了你刚贴的代码,发现我上面有一段转错了
type
OPENDEVICE=function (nMyAddress;hWnd:THandle):Pointer;stdcall;
RECVEDTION=procedure (lpEdition:LPCTSTR);
CONNECT=function (pDevice:Pointer;lpCommDef:LPCTSTR):boolean;
SETADDLOG=procedure (pDevice:Pointer;bAddLog:boolean);
SETINNERCODE=procedure (pDevice;Pointer;bBig5:boolean);
SETINNERCMD=procedure (pDevice:Pointer;bInner:boolean);
SETCOMMKEY=procedure (pDevice:Pointer;lpCommKey:CPCTSTR);
SETWAITTIME=procedure (pDevice:Pointer;dwWaitTime:Word);
STARTTICDMCMD=function (pDevice:Pointer;nAddress,,Command:Integer;pParameters:Pointer=nil;nSizeOfParamter:Integer=0):Pointer;
GETSIZEOFDATA=function (pCommand:Pointer):Integer;
GETADATA=funcction (pCommand,pDataBuffer:Pointer;nSize:Integer):boolean;
GETCMDRESULT=function (pCommand:Pointer):Integer;
ENDICDMCMD=procedure (pCommand:Pointer);
DISCONNECT=function (pDevice:Pointer):boolean;
CLOSEDEVICE=procedure (pDevice:Pointer);
SETMYADDRESS=procedure (pDevice:Pointer;nAddress:Integer);

SENDFRAME=procedure (pDevice:Pointer;lpSendFrm:LPCTSTR);
CLEARRECVSTR=procedure (pDevice:Pointer);
RECVSTREAM=function (pDevice:Pointer;lprecvStrL:LPTSTR):boolean;
RECVHDLC=function (pDevice:Pointer;lpRecvStr:LPTSTR):boolean;

TDllCall=class(TObject)
public
constructor Create;
Destructor Destroy;override;
hLibrary:THandle;//HINSTANCE
m_File:TMemoryStream;
m_pActReturn:Pointer;
nSizeOfData:Integer;
bGetData:boolean;
nInfoReturn,nTagAdr,nMyAdr:Integer;
bConnect,bDisConnect:boolean;
nFileHandle,nFileHandle1:Integer;

{这里我刚才理解为类型,现在才知道是DLL调用,但是现在你也只是变更,需要在Create中用LoadLibrary,GetProcAddress}
lpSendFrame:SENDFRAME;
lpClearRecvStr:CLEARRECVSTR;
lpRecvStream:RECVSTREAM;
lpRecvHDLC:RECVHDLC;

lpOpenDevice:OPENDEVICE;
lpRecvEdition:RECVEDITION;
lpConnect:CONNECT;
lpSetAddLog;SETADDLOG;
lpSetInnerCode:SETINNERCODE;
lpSetInnerCmd:SETINNERCMD;
lpSetWaitTime:SETWAITTIME;
lpSetCommKey:SETCOMMKEY;
lpStartICDMCmd:STARTICDMCMD;
lpSetSizeOfData:GETSIZEOFDATA;
lpGetData:GETDATA;
lpGetCmdResult:GETCMDRESULT;
lpEndICDMCmd:ENDICDMCMD;
lpDisConnect:DISCONNECT;
lpCloseDevice:CLOSEDEVICE;

function LoadFunction():boolean;
function ShowMessage(nMessage,nFontmsg:Integer):String;
function AddZero(strData:String;nLength:integer):String;
function myatoi(chChar:Char):Integer;
function Learch(const strSrc:String;chChar):String;
function HexToStr(n:Integer):String;
procedure WriteFile(nAdr,nInfoReturn,nHandle:Integer;strSectorNum,strOldAKey,StrOldOldBKey,strnewAKey,strNewBKey:String);
function AddAttGuardRecord(nCount:Integer;CardRecord:ATTGUARDRECORD):sTRING;
function AddPOSrecord(nCount:Integer;CardRecord:POSRECORD ):String;
function WriteAttGuardFile(nCount:Integer;CardRecord:ATTGUARDRECORD ):Integer;
function WritePOSFile(nCount:Integer;CardRecord:POSRECORD ):integer;

//下面的代码应该是引用DLL的代码,不知道有没有错,很久没有用C了
end;
 
lpGetData(m_pDllCall->m_pActReturn, &nAdr, nLength);
函数是:BOOL lpGetData(void* pCommand, void* pDataBuffer, int nSize)
----
在C中&是引用地址,而在delphi中引用地址是@
如下面的例子
Type
PInteger=^Integer;//那么
procedure A(AA:PInteger);


var
a:Integer;
begin
a := 1;
A(@a);
end;
 
接受答案了.
 
后退
顶部