Sign in to follow this  

win32 RPC (Does anybody familiar with it?)

This topic is 4376 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The first problem is how to declare function in IDL which returns array of strings via an [out] parameter. I tried something like this: BOOL method([in, out]int *size, [in, out, siring, size_is(*size)] wchar_t** arr), but i've got GPF exception somewhere in stub/marshialling code depths. The second problem is how to handle memory correctly and how to avoid memory leaks. Do i need to allocate memory with midl_user_allocate() in callee and midl_user_free() in caller?

Share this post


Link to post
Share on other sites
First, I'll promote two articles I've written on CodeProject:

http://www.codeproject.com/internet/rpcintro1.asp
http://www.codeproject.com/internet/rpcintro2.asp

But I'm not sure that these will help you on this rather complicated matter.

The best way of solving it is to provide your own marshaller and serialize the actual string array. Assuming C++:


BOOL Server_Method(
[out] DWORD* pdwOutBufferSize,
[out, size_is(, *pdwOutBufferSize)] BYTE** ppbOutBuffer);




Client

BOOL Server_MethodWrapper(std::vector<std::wstring>& rstrvec)
{
DWORD dwOutBufferSize = 0;
BYTE* pbOutBuffer = NULL;

const BOOL b = Server_MethodHelper(&dwOutBufferSize, &pbOutBuffer);
if (b)
{
StreamReader oStreamReader(pbOutBuffer, dwOutBufferSize);
Utilities::Read(rstrvec, oStreamReader);
midl_user_free(pbOutBuffer);
}

return b;
}

BOOL Server_MethodHelper(DWORD* pdwOutBufferSize, BYTE** ppbOutBuffer)
{
BOOL b;

RpcTryExcept
{
b = ::Server_Method(pdwOutBufferSize, ppbOutBuffer);
}
RpcExcept(1)
{
b = FALSE;
}
RpcEndExcept;

return b;
}




Server

BOOL Server_Method(
/* [out] */ DWORD *pdwOutBufferSize,
/* [size_is][size_is][out] */ BYTE **ppbOutBuffer)
{
*pdwOutBufferSize = 0;
*ppbOutBuffer = NULL;

const std::vector<std::wstring>& rstrvec = ...;

StreamWriter oStreamWriter;
Utilities::Write(rstrvec, oStreamWriter);

const StreamBuffer oOutBuffer = oStreamWriter.DetachBuffer();
*pdwOutBufferSize = oOutBuffer.muBufferSize;
*ppbOutBuffer = oOutBuffer.mpBuffer;
return TRUE;
}




Notes: StreamWriter allocates memory using midl_user_allocate, but it doesn't free it, the RPC runtime takes care of that.

Share this post


Link to post
Share on other sites
Quote:
First, I'll promote two articles I've written on CodeProject:

Thanks, very useful.
Quote:
Original post by d000hg
Anyway I strongly suggest you get this moved to 'general prgramming' since it has nothing to do with games.

I'm sorry, but 'Game Programming' and 'General programming' forum titles looks similar and placed close to eachother.
Moderator: Please move this topic to General programming.

Share this post


Link to post
Share on other sites

This topic is 4376 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this