很简单,记住几个要点就可以任意开发了:
手机端:
动态库里面的函数参数必须是这样的:DWORD cbInput, BYTE *pInput, DWORD *pcbOutput, BYTE **ppOutput, IRAPIStream *pIRAPIStream;类型最好不要改动,参数名倒无所谓;其中 cbInput 就传入缓冲区的长度,pInput 是传入缓冲区,pcbOutput 是传出缓冲区的长度,ppOutput 是传出缓冲区,pIRAPIStream 如果不是使用流模式的话,一些设为 NULL 就行了。
添加 DEF 文件,并把输出函数添加进去。
PC端:
代码
HRESULT hr;
hr = CeRapiInit();
DWORD dwOut;
PBYTE pOut;
CString temp;
hr = CeRapiInvoke(_T("TestLib.dll"), _T("CeTest"), 0, NULL, &dwOut, &pOut, NULL, 0);
if (hr == S_OK) {
temp = toWideString(pOut, dwOut);
}else{
temp.Format(_T("Error:%u"), hr);
}
MessageBox(temp, _T(""));
CeRapiUninit();
hr = CeRapiInit();
DWORD dwOut;
PBYTE pOut;
CString temp;
hr = CeRapiInvoke(_T("TestLib.dll"), _T("CeTest"), 0, NULL, &dwOut, &pOut, NULL, 0);
if (hr == S_OK) {
temp = toWideString(pOut, dwOut);
}else{
temp.Format(_T("Error:%u"), hr);
}
MessageBox(temp, _T(""));
CeRapiUninit();
MOBILE:
代码
int CeTest(DWORD cbInput, BYTE *pInput, DWORD *pcbOutput, BYTE **ppOutput, IRAPIStream *pIRAPIStream){
char* result = "Hello World!";
int datalen = strlen(result);
*ppOutput = (BYTE*)LocalAlloc(LPTR, datalen);
if(*ppOutput){
memset(*ppOutput, 0, datalen);
memcpy(*ppOutput, result, datalen);
*pcbOutput = datalen;
}else{
*pcbOutput = 0;
}
return 0;
}
char* result = "Hello World!";
int datalen = strlen(result);
*ppOutput = (BYTE*)LocalAlloc(LPTR, datalen);
if(*ppOutput){
memset(*ppOutput, 0, datalen);
memcpy(*ppOutput, result, datalen);
*pcbOutput = datalen;
}else{
*pcbOutput = 0;
}
return 0;
}