Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i followed this tutorial about creating a server and client program using RPC and downloaded the source code from it http://www.aspfree.com/c/a/net/introduction-to-rpc-on-windows-part-i/

but when i ran the code "Runtime exception occured: 5" displayed which i know means access denied.

i debugged the program and found that the problem was with the line
C++
NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR *) _StubMsg.Buffer );


here is the full show function:
C++
  void Show( 
    /* [string][in] */ const unsigned char __RPC_FAR *szMsg)
{

    RPC_BINDING_HANDLE _Handle  =   0;

    RPC_MESSAGE _RpcMessage;

    MIDL_STUB_MESSAGE _StubMsg;

    if(!szMsg)
        {
        RpcRaiseException(RPC_X_NULL_REF_POINTER);
        }
    RpcTryFinally
        {
        NdrClientInitializeNew(
                          ( PRPC_MESSAGE  )&_RpcMessage,
                          ( PMIDL_STUB_MESSAGE  )&_StubMsg,
                          ( PMIDL_STUB_DESC  )&DoRPC_StubDesc,
                          0);


        _Handle = hDoRPCBinding;


        _StubMsg.BufferLength = 12U;
        NdrConformantStringBufferSize( (PMIDL_STUB_MESSAGE) &_StubMsg,
                                       (unsigned char __RPC_FAR *)szMsg,
                                       (PFORMAT_STRING) &__MIDL_TypeFormatString.Format[4] );

        NdrGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg, _StubMsg.BufferLength, _Handle );

        NdrConformantStringMarshall( (PMIDL_STUB_MESSAGE)& _StubMsg,
                                     (unsigned char __RPC_FAR *)szMsg,
                                     (PFORMAT_STRING) &__MIDL_TypeFormatString.Format[4] );

        NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR *) _StubMsg.Buffer );

        }
    RpcFinally
        {
        NdrFreeBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg );

        }
    RpcEndFinally

}


and here's some code from main:
C++
RpcTryExcept
    {
        // Calls the RPC function. The hDoRPCBinding binding handle
        // is used implicitly.
        // Connection is done here.
        const unsigned char szMsg[] = "Client: I Can RPC Now!";
        Show(szMsg);
    }
    RpcExcept(1)
    {
        printf("Runtime exception occured: %d\n",RpcExceptionCode());
    }
    RpcEndExcept


so when debugging it jumped to the RpcExcept line when it reached NdrSendReceive
please help i have no idea how to fix this problem
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900