// // DllCall.cpp : implementation file
#include <vcl.h>
#include "DllCall.h"
/////////////////////////////////////////////////////////////////////////////
__fastcall TDllCall::TDllCall()
{
nTagAdr = 0;
bConnect = FALSE;
bDisConnect = TRUE;
}/////////////////////////////////////////////////////////////////////////////
__fastcall TDllCall::~TDllCall()
{
}/////////////////////////////////////////////////////////////////////////////
BOOL __fastcall TDllCall::LoadFunction()
{
lpOpenDevice = (OPENDEVICE*)::GetProcAddress(hLibrary, "OpenDevice");
if(lpOpenDevice == NULL)
{
FreeLibrary(hLibrary);
return FALSE;
} lpRecvEdition = (RECVEDITION*)::GetProcAddress(hLibrary, "RecvEdition");
if(lpRecvEdition == NULL)
return FALSE; lpSetMyAddress = (SETMYADDRESS*)::GetProcAddress(hLibrary, "SetMyAddress");
if(lpSetMyAddress == NULL)
return FALSE; lpConnect = (CONNECT*)::GetProcAddress(hLibrary, "ConnectPort");
if(lpConnect == NULL)
return FALSE; lpSetAddLog = (SETADDLOG*)::GetProcAddress(hLibrary, "SetAddLog");
if(lpSetAddLog == NULL)
return FALSE; lpSetInnerCode = (SETINNERCODE*)::GetProcAddress(hLibrary, "SetInnerCode");
if(lpSetInnerCode == NULL)
return FALSE; lpSetInnerCmd = (SETINNERCMD*)::GetProcAddress(hLibrary, "SetInnerCmd");
if(lpSetInnerCmd == NULL)
return FALSE; lpSetWaitTime = (SETWAITTIME*)::GetProcAddress(hLibrary, "SetWaitTime");
if(lpSetWaitTime == NULL)
return FALSE; lpSetCommKey = (SETCOMMKEY*)::GetProcAddress(hLibrary, "SetCommKey");
if(lpSetCommKey == NULL)
return FALSE; lpStartICDMCmd = (STARTICDMCMD*)::GetProcAddress(hLibrary, "StartICDMCommand");
if(lpStartICDMCmd == NULL)
return FALSE; lpGetSizeOfData = (GETSIZEOFDATA*)::GetProcAddress(hLibrary, "GetSizeOfData");
if(lpGetSizeOfData == NULL)
return FALSE; lpGetData = (GETDATA*)::GetProcAddress(hLibrary, "GetData");
if(lpGetData == NULL)
return FALSE; lpGetCmdResult = (GETCMDRESULT*)::GetProcAddress(hLibrary, "GetCmdResult");
if(lpGetCmdResult == NULL)
return FALSE; lpEndICDMCmd = (ENDICDMCMD*)::GetProcAddress(hLibrary, "EndICDMCommand");
if(lpEndICDMCmd == NULL)
return FALSE; lpDisConnect = (DISCONNECT*)::GetProcAddress(hLibrary, "DisConnectPort");
if(lpDisConnect == NULL)
return FALSE; lpCloseDevice = (CLOSEDEVICE*)::GetProcAddress(hLibrary, "CloseDevice");
if(lpCloseDevice == NULL)
return FALSE;
lpSendFrame = (SENDFRAME*)::GetProcAddress(hLibrary, "SendFrame");
if(lpSendFrame == NULL)
return FALSE; lpClearRecvStr = (CLEARRECVSTR*)::GetProcAddress(hLibrary, "ClearRecvStr");
if(lpClearRecvStr == NULL)
return FALSE; lpRecvStream = (RECVSTREAM*)::GetProcAddress(hLibrary, "RecvStream");
if(lpRecvStream == NULL)
return FALSE; lpRecvHDLC = (RECVHDLC*)::GetProcAddress(hLibrary, "RecvHDLC");
if(lpRecvHDLC == NULL)
return FALSE; return TRUE;
}/////////////////////////////////////////////////////////////////////////////
String __fastcall TDllCall::ShowMessage(int nMessage, int nFontMsg)
{
String strResult;
INFOCODE nInfoCode = (INFOCODE)nMessage;
FONT nFont = (FONT)nFontMsg;
switch(nFont)
{
case nUSEnglish:
if(nInfoCode == nSendSuccess || nInfoCode == nSuccess ||
nInfoCode == nRecvSuccess || nInfoCode == nRecvEmpty)
strResult = "Success";
else
strResult = "Failure";
break;
case nPRCChinese:
if(nInfoCode == nSendSuccess || nInfoCode == nSuccess ||
nInfoCode == nRecvSuccess || nInfoCode == nRecvEmpty)
strResult = "成功";
else
strResult = "失败";
break;
case nTaiWanChinese:
if(nInfoCode == nSendSuccess || nInfoCode == nSuccess ||
nInfoCode == nRecvSuccess || nInfoCode == nRecvEmpty)
strResult = "Θ";
else
strResult = "ア毖";
break;
} return strResult;
}String __fastcall TDllCall::AddZero(String strData, int nLength)
{
while(strData.Length() < nLength)
strData = "0" + strData;
return strData;
}
#include <vcl.h>
#include "DllCall.h"
/////////////////////////////////////////////////////////////////////////////
__fastcall TDllCall::TDllCall()
{
nTagAdr = 0;
bConnect = FALSE;
bDisConnect = TRUE;
}/////////////////////////////////////////////////////////////////////////////
__fastcall TDllCall::~TDllCall()
{
}/////////////////////////////////////////////////////////////////////////////
BOOL __fastcall TDllCall::LoadFunction()
{
lpOpenDevice = (OPENDEVICE*)::GetProcAddress(hLibrary, "OpenDevice");
if(lpOpenDevice == NULL)
{
FreeLibrary(hLibrary);
return FALSE;
} lpRecvEdition = (RECVEDITION*)::GetProcAddress(hLibrary, "RecvEdition");
if(lpRecvEdition == NULL)
return FALSE; lpSetMyAddress = (SETMYADDRESS*)::GetProcAddress(hLibrary, "SetMyAddress");
if(lpSetMyAddress == NULL)
return FALSE; lpConnect = (CONNECT*)::GetProcAddress(hLibrary, "ConnectPort");
if(lpConnect == NULL)
return FALSE; lpSetAddLog = (SETADDLOG*)::GetProcAddress(hLibrary, "SetAddLog");
if(lpSetAddLog == NULL)
return FALSE; lpSetInnerCode = (SETINNERCODE*)::GetProcAddress(hLibrary, "SetInnerCode");
if(lpSetInnerCode == NULL)
return FALSE; lpSetInnerCmd = (SETINNERCMD*)::GetProcAddress(hLibrary, "SetInnerCmd");
if(lpSetInnerCmd == NULL)
return FALSE; lpSetWaitTime = (SETWAITTIME*)::GetProcAddress(hLibrary, "SetWaitTime");
if(lpSetWaitTime == NULL)
return FALSE; lpSetCommKey = (SETCOMMKEY*)::GetProcAddress(hLibrary, "SetCommKey");
if(lpSetCommKey == NULL)
return FALSE; lpStartICDMCmd = (STARTICDMCMD*)::GetProcAddress(hLibrary, "StartICDMCommand");
if(lpStartICDMCmd == NULL)
return FALSE; lpGetSizeOfData = (GETSIZEOFDATA*)::GetProcAddress(hLibrary, "GetSizeOfData");
if(lpGetSizeOfData == NULL)
return FALSE; lpGetData = (GETDATA*)::GetProcAddress(hLibrary, "GetData");
if(lpGetData == NULL)
return FALSE; lpGetCmdResult = (GETCMDRESULT*)::GetProcAddress(hLibrary, "GetCmdResult");
if(lpGetCmdResult == NULL)
return FALSE; lpEndICDMCmd = (ENDICDMCMD*)::GetProcAddress(hLibrary, "EndICDMCommand");
if(lpEndICDMCmd == NULL)
return FALSE; lpDisConnect = (DISCONNECT*)::GetProcAddress(hLibrary, "DisConnectPort");
if(lpDisConnect == NULL)
return FALSE; lpCloseDevice = (CLOSEDEVICE*)::GetProcAddress(hLibrary, "CloseDevice");
if(lpCloseDevice == NULL)
return FALSE;
lpSendFrame = (SENDFRAME*)::GetProcAddress(hLibrary, "SendFrame");
if(lpSendFrame == NULL)
return FALSE; lpClearRecvStr = (CLEARRECVSTR*)::GetProcAddress(hLibrary, "ClearRecvStr");
if(lpClearRecvStr == NULL)
return FALSE; lpRecvStream = (RECVSTREAM*)::GetProcAddress(hLibrary, "RecvStream");
if(lpRecvStream == NULL)
return FALSE; lpRecvHDLC = (RECVHDLC*)::GetProcAddress(hLibrary, "RecvHDLC");
if(lpRecvHDLC == NULL)
return FALSE; return TRUE;
}/////////////////////////////////////////////////////////////////////////////
String __fastcall TDllCall::ShowMessage(int nMessage, int nFontMsg)
{
String strResult;
INFOCODE nInfoCode = (INFOCODE)nMessage;
FONT nFont = (FONT)nFontMsg;
switch(nFont)
{
case nUSEnglish:
if(nInfoCode == nSendSuccess || nInfoCode == nSuccess ||
nInfoCode == nRecvSuccess || nInfoCode == nRecvEmpty)
strResult = "Success";
else
strResult = "Failure";
break;
case nPRCChinese:
if(nInfoCode == nSendSuccess || nInfoCode == nSuccess ||
nInfoCode == nRecvSuccess || nInfoCode == nRecvEmpty)
strResult = "成功";
else
strResult = "失败";
break;
case nTaiWanChinese:
if(nInfoCode == nSendSuccess || nInfoCode == nSuccess ||
nInfoCode == nRecvSuccess || nInfoCode == nRecvEmpty)
strResult = "Θ";
else
strResult = "ア毖";
break;
} return strResult;
}String __fastcall TDllCall::AddZero(String strData, int nLength)
{
while(strData.Length() < nLength)
strData = "0" + strData;
return strData;
}
解决方案 »
- 生僻的dxNavBar控件应用!!!
- DELPHI中怎么设置才能让编译后的EXE文件可以那到其他没有D的机子里运行?
- 事务问题!在线等待!!!
- 高手别嫌弃,就剩这么多分了,请问我这样给dbgrid的column的picklist动态赋值为什么不起作用?
- 请问如何调用 TdxTileControlItem 里的窗口过程和函数
- 不需要让用户按Alt+Enter、Ctrl+Alt+Del、Ctrl+Esc等功能键
- 动态数字接受通讯事件中,
- 在delphi中怎样制作动态菜单,要显示的菜单项从数据库中获取??
- 动态阵列如何设定成 Low = -20 (负值)
- 大家谈谈软件工程吧
- 深圳有招delphi程序员的吗?
- 请问如何在asp客户端读取非接触式ID卡?
int __fastcall TDllCall::myatoi(char chChar)
{
if (chChar >= '0' && chChar <= '9')
return chChar - '0';
else if (chChar >= 'a' && chChar <= 'f')
return chChar - 'a' + 10;
else if (chChar >= 'A' && chChar <= 'F')
return chChar - 'A' + 10;
else if (chChar == ' ')
return -1;
else
return -2;
}
String __fastcall TDllCall::HexToStr(int n)
{
String str;
char ch[10];
wsprintf(ch, "%02x", (BYTE)n);
str = ch;
return str;
}
String __fastcall TDllCall::Learch(const String& strSrc, char chChar)
{
String strDest;
for(int iLoop = 1; iLoop <= strSrc.Length(); iLoop ++)
if (strSrc[iLoop] != chChar)
strDest += (char)strSrc[iLoop];
return strDest;
}void __fastcall TDllCall::WriteFile(int nAdr, int nInfoReturn, int nHandle, String strSectorNum,
String strOldAKey, String strOldBKey, String strNewAKey, String strNewBKey)
{
SYSTEMTIME LocalTime;
GetLocalTime(&LocalTime);
String strAdr = "Address:" + AddZero(IntToStr(nAdr), 3) + ",";
String strHandle = "Handle:" + AddZero(IntToStr(nHandle), 3) + ",";
String strSector = "Sector:" + strSectorNum + ",";
String strKey = "Old A_Key:" + strOldAKey + ",Old B_Key:" + strOldBKey +
"\r\n" + "New A_Key:" + strNewAKey + ",New B_Key:" + strNewBKey;
String strRlt;
if(nInfoReturn == nSuccess)
strRlt = "Result:Success,";
else
strRlt = "Result: Fail ,";
String strDate = AddZero(IntToStr(LocalTime.wYear), 4) + "-" +
AddZero(IntToStr(LocalTime.wMonth), 2) + "-" +
AddZero(IntToStr(LocalTime.wDay), 2) + ",";
String strTime = AddZero(IntToStr(LocalTime.wHour), 2) + ":" +
AddZero(IntToStr(LocalTime.wMinute), 2) + ":" +
AddZero(IntToStr(LocalTime.wSecond), 2);
String StrRecord = strAdr + strHandle + strSector + strRlt + strDate + strTime
+ "\r\n" + strKey + "\r\n\r\n";
FileSeek(nFileHandle, 0, 2);
FileWrite(nFileHandle, StrRecord.c_str(), StrRecord.Length());
}String __fastcall TDllCall::AddAttGuardRecord(int nCount, ATTGUARDRECORD CardRecord)
{
String strCount = AddZero(IntToStr(nCount), 5);
String strPersonID, strFlowID1, strFlowID2;
for (int nLoop = 0; nLoop < 7; nLoop ++)
strPersonID += CardRecord.tPersonID.str[nLoop];
String strYear = AddZero(IntToStr(CardRecord.nYear), 4);
String strMonth = AddZero(IntToStr(CardRecord.nMonth), 2);
String strDay = AddZero(IntToStr(CardRecord.nDay), 2);
String strHour = AddZero(IntToStr(CardRecord.nHour), 2);
String strMinute = AddZero(IntToStr(CardRecord.nMinute), 2);
String strSecond = AddZero(IntToStr(CardRecord.nSecond), 2);
String strAdr = AddZero(IntToStr(CardRecord.nAdr), 3);
String strIsOnDuty, strIsBC, str;
if(CardRecord.bOnDuty)
strIsOnDuty = "1";
else
strIsOnDuty = "0";
if(CardRecord.bBC)
strIsBC = "1";
else
strIsBC = "0";
strFlowID1 = strYear.SubString(3, 2) + strMonth + strDay;
strFlowID2 = strAdr + strCount;
str = strFlowID1 + strFlowID2 + "," + strPersonID + "," + strYear + "-" + strMonth + "-" +
strDay + "," + strHour + ":" + strMinute + ":" + strSecond + "," +
strIsOnDuty + "," + strIsBC + "\r\n";
return str;
}String __fastcall TDllCall::AddPOSRecord(int nCount, POSRECORD CardRecord)
{
String str, strPersonID, strFlowID1, strFlowID2;return str;}int __fastcall TDllCall::WriteAttGuardFile(int nCount, ATTGUARDRECORD CardRecord)
{
String strRecord, strPersonID, strFlowID1, strFlowID2;
String strFlag = "0";
SYSTEMTIME LocalTime;
GetLocalTime(&LocalTime);
String strCount = AddZero(IntToStr(nCount), 5);
for (int nLoop = 0; nLoop < 7; nLoop ++)
strPersonID += CardRecord.tPersonID.str[nLoop];
String strYear = AddZero(IntToStr(CardRecord.nYear), 4);
String strMonth = AddZero(IntToStr(CardRecord.nMonth), 2);
String strDay = AddZero(IntToStr(CardRecord.nDay), 2);
String strHour = AddZero(IntToStr(CardRecord.nHour), 2);
String strMinute = AddZero(IntToStr(CardRecord.nMinute), 2);
String strSecond = AddZero(IntToStr(CardRecord.nSecond), 2);
String strAdr = AddZero(IntToStr(CardRecord.nAdr), 3);
String strIsOnDuty, strIsBC;
if(CardRecord.bOnDuty)
strIsOnDuty = "1";
else
strIsOnDuty = "0";
if(CardRecord.bBC)
strIsBC = "1";
else
strIsBC = "0";
if(LocalTime.wYear != CardRecord.nYear)
strFlag = "1";
if(LocalTime.wMonth != CardRecord.nMonth)
strFlag = "1";
if(LocalTime.wDay != CardRecord.nDay)
strFlag = "1";
if(CardRecord.nHour > 23 || CardRecord.nHour < 0)
strFlag = "1";
if(CardRecord.nMinute > 59 || CardRecord.nMinute < 0)
strFlag = "1"; strFlowID1 = strYear.SubString(3, 2) + strMonth + strDay;
strFlowID2 = strAdr + strCount;
strRecord = strFlowID1 + strFlowID2 + "," + strPersonID + "," + strYear + "-" + strMonth + "-" +
strDay + "," + strHour + ":" + strMinute + ":" + strSecond + "," + strIsOnDuty + "," +
strIsBC + "," + strFlag + "\r\n";
FileSeek(nFileHandle1, 0, 2);
return FileWrite(nFileHandle1, strRecord.c_str(), strRecord.Length());
}int __fastcall TDllCall::WritePOSFile(int nCount,POSRECORD CardRecord)
{ String strRecord;
String strFlag = "0";
SYSTEMTIME LocalTime;
GetLocalTime(&LocalTime);
//序号
String strCount = AddZero(IntToStr(nCount), 5);
//帐号
String strCardID = AddZero(IntToStr(CardRecord.nInfoID), 6);
//消费额
String strConsumeMoney = AddZero(IntToStr(CardRecord.nMoneyCent), 5);
//余额
String strBlance = AddZero(IntToStr(CardRecord.nBalance), 6);
//消费流水号
String strTotalCount = AddZero(IntToStr(CardRecord.nTotalTimes), 5);
//操作员号
String strOpert = AddZero(IntToStr(CardRecord.nOperatorNum), 3);
//date , time
String strYear = AddZero(IntToStr(CardRecord.nYear), 4);
String strMonth = AddZero(IntToStr(CardRecord.nMonth), 2);
String strDay = AddZero(IntToStr(CardRecord.nDay), 2);
String strHour = AddZero(IntToStr(CardRecord.nHour), 2);
String strMinute = AddZero(IntToStr(CardRecord.nMinute), 2);
String strSecond = AddZero(IntToStr(CardRecord.nSecond), 2); String strAdr = AddZero(IntToStr(CardRecord.nDMAdr), 3);
String strNormal, strCancel;
String strReload; if(CardRecord.bNormal)
strNormal = "1";
else
strNormal = "0";
if(CardRecord.bCancel)
strCancel = "1";
else
strCancel = "0";
if(CardRecord.bReload)
strReload = "1";
else
strReload = "0";
//非法日期、时间判断
if(LocalTime.wYear != CardRecord.nYear)
strFlag = "1";
if(LocalTime.wMonth != CardRecord.nMonth)
strFlag = "1";
if(LocalTime.wDay != CardRecord.nDay)
strFlag = "1";
if(CardRecord.nHour > 23 || CardRecord.nHour < 0)
strFlag = "1";
if(CardRecord.nMinute > 59 || CardRecord.nMinute < 0)
strFlag = "1"; strRecord = strCount + "," + strCardID + "," + strConsumeMoney + ","
+ strBlance + "," + strTotalCount + "," + strOpert + "," +
strYear + "-" + strMonth + "-" + strDay + "," +
strHour + ":" + strMinute + ":" + strSecond + "," +
strNormal + "," + strCancel + "," + strReload + "," +
strFlag + "," + strAdr + "\r\n";
FileSeek(nFileHandle1, 0, 2);
return FileWrite(nFileHandle1, strRecord.c_str(), strRecord.Length());
}
都不是很复杂的东西,自己一句一句改过去就可以了