Dephi调用C++的DLL问题?怎么定义?(50分)

L

lglhsy

Unregistered / Unconfirmed
GUEST, unregistred user!
===VC++ ================================================================
#undef LPTSTR
typedef BYTE RSI_ID[5];

RSI_DLL RSI_DATA_ERROR RSI_API rsiTextToID(LPCTSTR text, RSI_ID id);
RSI_DLL RSI_DATA_ERROR RSI_API rsiIDToText(RSI_ID id, LPTSTR text);
===Delphi================================================================
Type RSI_ID=record
b0 : Byte;
b1 : Byte;
b2 : Byte;
b3 : Byte;
b4 : Byte;
end;
Function rsiIDToText(ID:RSI_ID;text:pchar) :RSI_DATA_ERROR; stdcall; external 'rsidll32.dll';
Function rsiTextToID(text:pchar;ID:RSI_ID) :RSI_DATA_ERROR; stdcall; external 'rsidll32.dll';

这样总是会出现地址错误??
var
id:RSI_ID;
str_id:pchar;
begin
Result:= rsiIDToText(ur.ID,str_id);
end;
在delphi里要怎样定义和怎样调用呢?
 
Type RSI_ID= packed record
b0 : Byte;
b1 : Byte;
b2 : Byte;
b3 : Byte;
b4 : Byte;
end;

var
id:RSI_ID;
str_id:String;
begin
SetLength(str_id, 100); //PChar一定要先分配内存
Result:= rsiIDToText(ur.ID,PChar(str_id));
end;

 
看看下面三个在C++中是如何定义的:
RSI_DLL RSI_DATA_ERROR RSI_API
 
var
id:RSI_ID;
str_id:String;
begin
SetLength(str_id, 100); //PChar一定要先分配内存
Result:= rsiIDToText(ur.ID,PChar(str_id));
end;
这样也不行。。还是地址错误??
Function rsiIDToText(ID:RSI_ID;text:pchar) :RSI_DATA_ERROR; stdcall; external 'rsidll32.dll';
(ID:RSI_ID;text:pchar)text 是不是用pchar?? text是要带出返回值...
可是这样呢?
Function rsiIDToText(ID:RSI_ID;Var text:pchar) :RSI_DATA_ERROR; stdcall; external 'rsidll32.dll';
也是不行...!!!

怎样定义和怎样调用???


 
#ifdef _WIN32 // 32-bit DLL
#ifdef RSI_BUILDING_DLL // export for the DLL
#define RSI_DLL __declspec(dllexport)
#else // import for applications
#define RSI_DLL __declspec(dllimport)
#endif
#define RSI_API __stdcall
#else // 16-bit DLL
#define RSI_DLL // rely on .DEF file for exports

typedef enum
{
RSI_DATA_OK, // No data error
RSI_ERROR_ID_CHAR, // ASCII ID character out of range Ox30-Ox3F
RSI_ERROR_AUTHORITY_LEVEL, // Authority level out of range 0-5
RSI_ERROR_REJECT_THRESHOLD, // Reject threshold out of range
RSI_ERROR_TIME_ZONE, // Time zone out of range 0-61
RSI_ERROR_YEAR, // added by Prasanth Pulavarthi
RSI_ERROR_MONTH, // Month out of range
RSI_ERROR_DAY,
RSI_ERROR_HOUR, // added by Prasanth Pulavarthi
RSI_ERROR_MINUTE,
RSI_ERROR_SECOND,
RSI_ERROR_TIME_20K,
RSI_ERROR_READER_ADDR, // added by Prasanth Pulavarthi
RSI_ERROR_FACILITY_CODE, // added by Prasanth Pulavarthi
RSI_ERROR_ID_LENGTH, // added by Prasanth Pulavarthi
RSI_ERROR_NUM_TRIES, // added by Prasanth Pulavarthi
RSI_ERROR_DURESS_CHAR, // added by Prasanth Pulavarthi
RSI_ERROR_MSG_TEXT, // added by Prasanth Pulavarthi
RSI_ERROR_INTERVAL_TIME, // added by Prasanth Pulavarthi
RSI_ERROR_BELL_DURATION, // added by Prasanth Pulavarthi
RSI_ERROR_BUFFER_INVALID, // added by Prasanth Pulavarthi
RSI_ERROR_CHANNEL_INVALID, // used only by rsiGetDataError()
RSI_ERROR_SERIAL_MODE,
} RSI_DATA_ERROR;
 
Function rsiIDToText(var ID:ShortString;var text:ShortString) :integer; stdcall; external 'rsidll32.dll';
Function rsiTextToID(var text:ShortString;var ID:ShortString) :integer; stdcall; external 'rsidll32.dll';
 
把DLL发给我tseug@263.net
 
rsiTextToID和rsiIDToText 源程序如下:
/////////////////////////////////////////////////////////////////////////////
// Converts 0x01 0x23 0x45 0x67 0x89 into '0123456789'
RSI_DLL RSI_DATA_ERROR RSI_API rsiIDToText(RSI_ID id, LPTSTR text)
{
RSI_FUNCTION;

VERIFY_DATA(text != NULL, BUFFER_INVALID);

char tmp[2];
lstrcpy(text, "");
for (int j = 0; j < RSI_LEN_ID; j++)
{
_itoa(id[j] >> 4, tmp, 10);
lstrcat(text, tmp);
_itoa(id[j] & 0x0F, tmp, 10);
lstrcat(text, tmp);
}

return RSI_DATA_OK;
}

/////////////////////////////////////////////////////////////////////////////
// Converts '123456789' into 0x01 0x23 0x45 0x67 0x89
RSI_DLL RSI_DATA_ERROR RSI_API rsiTextToID(LPCTSTR text, RSI_ID id)
{
RSI_FUNCTION;

VERIFY_DATA(text != NULL, BUFFER_INVALID);

// clear the id buffer
memset(id, 0, sizeof(RSI_ID));

int idx = sizeof(RSI_ID) - 1;
TCHAR tmp[2];
for (int i = lstrlen(text) - 1; i >= 0; i -= 2)
{
VERIFY_DATA(IsCharAlphaNumeric(text) && !IsCharAlpha(text), ID_CHAR);
tmp[0] = text;
tmp[1] = 0;
id[idx] = (BYTE)atoi(tmp);
if (i - 1 >= 0)
{
VERIFY_DATA(IsCharAlphaNumeric(text[i - 1]) && !IsCharAlpha(text[i - 1]), ID_CHAR);
tmp[0] = text[i - 1];
tmp[1] = 0;
id[idx] |= (BYTE)atoi(tmp) << 4;
}
idx--;
}

return RSI_DATA_OK;
}
 
[:(], 这也要DLL,自己用Delphi写一个就可以了
 
二次开发
要操作控制是硬件...硬件供应商提供的DLL
所以我必需要用它提供的底层函数...
rsiTextToID只是一个底层函数...
 
rsiIDToText
原形: RSI_DATA_ERROR rsiIDToText(RSI_ID id, LPTSTR text);
参数: RSI_ID id: 一个 BCD 格式的使用者 ID 的数据结构LPTSTR
text:一个将会接收使用者 ID 正文字符串的指针
功能: 将一个 BCD 格式的使用者 ID 转换为一个正文格式的使用者 ID
返回: RSI_DATA_OK:成功由 rsiGetDataError 返回的错误值:失败

text参数是指针。要怎么定义才行?
 
你试试 text:array[1..5] of Byte
rsiIDToText(ur.ID,text);

 
还是不行...
 
想不通VB这样就行了
Declare Function rsiIDToText Lib "rsidll32" (ID As Any, ByVal text As String) As Long
Dim text1 As String * 10
Call rsiIDToText(UserRec.ID, text1)
delphi就不行。。。DLL没有问题
 
up 现在有事处理
 
在C里RSI_ID[5]分配的是6字节地址0--5;明白了?
 
第一个参数ID没问题,第二个参数text:一个将会接收使用者 ID 正文字符串的指针
怎样定义都总是地址错误??试了很多。。。
 
顶部