I'm trying to organize data transfer between the server and the client. When using asynchronous calls using the MS RPC API, I was able to transfer data with the int type to the client side. But when I try to pass in a data structure, I'm having trouble.
idl file
interface Test
{
typedef struct _RPCData {
int length;
[size_is(length)] char* buffer;
} RPCData, * PRPCData;
RPCData* TransferData([in] handle_t hBinding, [in] RPCData* sendData);
}
Server
/* [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
...
}
Client
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);
...
}
As a result I get an error on the server:
Exception thrown at 0x763B0879 (rpcrt4.dll) in ServerDebug.exe: 0xC0000005: Access violation reading location 0x0000000D.
All examples of using asynchronous calls use int.