首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > WinCE >

PocketBuilder 调用WINCE API参数传递有关问题

2013-11-02 
PocketBuilder 调用WINCE API参数传递问题大家好,有家客户用PocketBuilder开发WINCE6.0设备的应用程序,需

PocketBuilder 调用WINCE API参数传递问题
大家好,有家客户用PocketBuilder开发WINCE6.0设备的应用程序,需要调用到我们提供dll的接口,比如:
int RF_ISO14443A_authentication(int iMode, int iBlock, UINT8 *pszKey, int iLenKey)
客户在传递第3个参数的时候遇到问题,这里的UINT8等同于unsigned char,客户的应用程序的对此参数的引入和定义如下:
FUNCTION integer RF_ISO14443A_authentication(int iMode,int iBlock,ref string pszKey, int iLenKey) library "DeviceAPI.dll"

string key_s1,key_s2=space(100)
string is_key='A1B2C3'
key_s1= is_key
key_s2 = f_hex_string(key_s1)

ll_i = RF_ISO14443A_authentication(0,8,key_s2,6)

WINCE 此API的一部分如下:

extern "C" DEVICEAPI_API int RF_ISO14443A_authentication(int iMode, int iBlock, UINT8 *pszKey, int iLenKey)
{
UINT8 i=0;
for(i=0;i<iLenKey;i++)
{
RETAILMSG(DEBUG, (TEXT("RF_ISO14443A_authentication()  pszKey[%d]=0x%x\r\n"),i,pszKey[i]));
}
return ISO14443A_authentication(iMode, iBlock, pszKey, iLenKey);
}

调试口输出的信息如下:
RF_ISO14443A_authentication()  pszKey[0]=0xa1
RF_ISO14443A_authentication()  pszKey[1]=0x0
RF_ISO14443A_authentication()  pszKey[2]=0xb2
RF_ISO14443A_authentication()  pszKey[3]=0x0
RF_ISO14443A_authentication()  pszKey[4]=0xc3
RF_ISO14443A_authentication()  pszKey[5]=0x0
应用层想传递的值是“A1B2C3”,为什么WINCE API这边却多了0x0,在此向大家请教了。
[解决办法]
RF_ISO14443A_authentication(0,8,key_s2,6)
这个函数之前,内存里key_s2它存储的是啥?
我觉得应该跟你打印的是一样的,如果一样的话就是转换的问题罗。
[解决办法]
高位为零,是不是传递了unicode编码哦
[解决办法]
更正一点,传送的也不是unicode,ascii码才会是高位为0,低位要小于128。更象是f_hex_string转换的问题。
这个看谁适配谁了,双方做好约定,按照约定进行处理。
[解决办法]
key_s2 = f_hex_string(key_s1)
这个处理获取是unicode
你讲接口参数类型改成WCHAR试试看。
[解决办法]
引用:
string 跟接收的类型UINT8* 一样吗?我估计在CE下应该是有差别的吧


引用:
UINT8* is_key='A1B2C3'
用这个试试就知道了


string 这个本身是unicode类型的。所以就不能用这个类型。
要用类是byte[]这样的类型吧。encoding.ascii.getbytes(string)不过这时c#的。

热点排行