我正在尝试组织服务器和客户端之间的数据传输。当使用 MS ROC API 使用异步调用时,我能够将 int 类型的数据传输到客户端。但是当我尝试传入数据结构时,我遇到了麻烦。
空闲文件
interface Test
{
typedef struct _RPCData {
int length;
[size_is(length)] char* buffer;
} RPCData, * PRPCData;
RPCData* TransferData([in] handle_t hBinding, [in] RPCData* sendData);
}
服务员
/* [async] */ void TransferData(
/* [in] */ IN OUT PRPC_ASYNC_STATE TransferData_AsyncHandle,
/* [in] */ handle_t hBinding,
/* [in] */ RPCData* sendData)
{
RPCData data;
data.buffer = (unsigned char*)"Test data";
data.length = 9;
RpcAsyncCompleteCall(TransferData_AsyncHandle, &data); // There's error here
...
}
客户
void SendData(LPCWSTR lpwszProto, LPCWSTR lpwszEndPoint, LPCWSTR lpwszHost, RPCData data)
{
...
RPC_ASYNC_STATE async;
RPC_WSTR szStringBinding = nullptr;
RpcStringBindingCompose(nullptr,lpwszProto,lpwszHost,lpwszEndPoint, nullptr, &szStringBinding);
RpcBindingFromStringBinding(szStringBinding, &PPE_IfHandle);
async.UserInfo = NULL;
async.NotificationType = RpcNotificationTypeEvent;
async.u.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
RpcAsyncInitializeHandle(&async, sizeof(RPC_ASYNC_STATE));
RPCData reciveData;
if (async.u.hEvent != 0)
{
RpcTryExcept
TransferData(&async, TEST_IfHandle, &data);
if (WaitForSingleObject(async.u.hEvent, INFINITE) == WAIT_FAILED) {}
RPCData reciveData;
RpcAsyncCompleteCall(&async, &reciveData);
RpcExcept(1)
....
RpcEndExcept
}
CloseHandle(async.u.hEvent);
...
}
结果我在服务器上收到一个错误:ServerDebug.exe 中的 0x763B0879 (rpcrt4.dll) 抛出异常:0xC0000005:访问冲突读取位置 0x0000000D.
所有使用异步调用的例子都使用int.