Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Visual-Studio TCP/IP Remote , +
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
NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR *) _StubMsg.Buffer );
 
here is the full show function:
  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:
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 10-Apr-13 23:20pm

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

  Print Answers RSS
0 OriginalGriff 459
1 Maciej Los 325
2 Sergey Alexandrovich Kryukov 234
3 DamithSL 233
4 BillWoodruff 200
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 11 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100