win32 RPC (Does anybody familiar with it?)
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?
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++:
Client
Server
Notes: StreamWriter allocates memory using midl_user_allocate, but it doesn't free it, the RPC runtime takes care of that.
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.
I've done COM but not raw RPC code, but does RPC use variants?
Anyway I strongly suggest you get this moved to 'general prgramming' since it has nothing to do with games.
Anyway I strongly suggest you get this moved to 'general prgramming' since it has nothing to do with games.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement