dertopper
10/20/2008 6:36:00 AM
On 20 Okt., 07:36, Ashutosh <smbs-m...@nospam.nospam> wrote:
> Hi,
> I have some code which was written around 8-10 years back and I really I
> don't have much idea what it does (no one in my team has either) other
> than that it connects to some other other service over the network. This
> code is in a VC++ DLL which is being used by a VB Application. We are
> planning to create a new application in C# which does all the work done
> by them. I tried searching the web, it shows some RPC NDR related to DCOM.
>
> Is it somewhere related to custom marshaling or in DCOM? Also, is it
> possible to achieve the same result somehow in .Net?
>
> A part of the code is
>
> int getConfig(
> /* [ref][out][in] */ struct rpcConfig __RPC_FAR *r)
> {
> RPC_BINDING_HANDLE _Handle = 0;
> int _RetVal;
> RPC_MESSAGE _RpcMessage;
> MIDL_STUB_MESSAGE _StubMsg;
> RpcTryFinally
> {
> NdrClientInitializeNew(
> ( PRPC_MESSAGE )&_RpcMessage,
> ( PMIDL_STUB_MESSAGE )&_StubMsg,
> ( PMIDL_STUB_DESC )&chrpc_StubDesc,
> 10);
> _Handle = hCHrpc;
> _StubMsg.BufferLength = 0U;
> NdrSimpleStructBufferSize( (PMIDL_STUB_MESSAGE) &_StubMsg,
> (unsigned char __RPC_FAR *)r,
> (PFORMAT_STRING)
> &__MIDL_TypeFormatString.Format[156] );
>
> NdrGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg,
> _StubMsg.BufferLength, _Handle );
>
> NdrSimpleStructMarshall( (PMIDL_STUB_MESSAGE)& _StubMsg,
> (unsigned char __RPC_FAR *)r,
> (PFORMAT_STRING)
> &__MIDL_TypeFormatString.Format[156] );
>
> NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char
> __RPC_FAR *) _StubMsg.Buffer );
>
> if ( (_RpcMessage.DataRepresentation & 0X0000FFFFUL) !=
> NDR_LOCAL_DATA_REPRESENTATION )
> NdrConvert( (PMIDL_STUB_MESSAGE) &_StubMsg, (PFORMAT_STRING)
> &__MIDL_ProcFormatString.Format[38] );
>
> NdrSimpleStructUnmarshall( (PMIDL_STUB_MESSAGE) &_StubMsg,
> (unsigned char __RPC_FAR * __RPC_FAR
> *)&r,
> (PFORMAT_STRING)
> &__MIDL_TypeFormatString.Format[156],
> (unsigned char)0 );
>
> _RetVal = *(( int __RPC_FAR * )_StubMsg.Buffer)++;
> }
> RpcFinally
> {
> NdrFreeBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg );
> }
> RpcEndFinally
> return _RetVal;
>
> }
At first glance I simply thought that this is standard code generated
by the MIDL compiler for a proxy-stub Dll. However, the function
getConfig is not part of a COM interface, so this method is apparently
hand-written (the author has certainly copy-pasted most of it from
MIDL generated code). The struct rpcConfig is not part of the standard
COM headers (at least not with the Platform SDK 2003), so I guess you
should search for the declaration of this struct. You should also look
for any calls of the function getConfig in the Dll code.
Regards,
Stuart