Click here to Skip to main content
15,895,142 members

NdrSendReceive access denied in RPC program

Member 8589499 asked:

Open original thread
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
Tags: C++, Visual Studio, TCP/IP, Remote

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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