getting RpcExceptionCode 5 with RPC code
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 36

Thread: getting RpcExceptionCode 5 with RPC code

  1. #1
    Join Date
    Mar 2012
    Posts
    99

    getting RpcExceptionCode 5 with RPC code

    i got the source code from this website:
    http://www.aspfree.com/c/a/net/intro...indows-part-i/

    and when i tried running the server and client i get Runtime exception occured:5
    in the client console

    i don't know how to fix it
    heres the client code:
    Code:
    // File DoRPC_Client.cpp
    #include <stdio.h>
    #include "..\RPC1_IDL\DoRPC.h"
    
    int main()
    {
       RPC_STATUS status;
       unsigned char* szStringBinding = NULL;
    
       // Creates a string binding handle.
       // This function formats the passed values in a 
       // predefined format for use by RPC. Just like printf
       // Connection is not done here.
       status = RpcStringBindingCompose(
          NULL, // UUID to bind to.
          (unsigned char*)("ncacn_ip_tcp"), // Use TCP/IP protocol.
          (unsigned char*)("localhost"), // TCP/IP network - the same machine as server
          (unsigned char*)("9191"), // TCP/IP port to use.
          NULL, 				// Protocol dependent network options to use.
          &szStringBinding); 		// String binding output.
    
       if (status)
          exit(status);
    
       // Validates the format of the string binding handle and converts
       // it to a binding handle.
       // Connection is not done here either.
       status = RpcBindingFromStringBinding(
          szStringBinding, // The string binding to validate.
          &hDoRPCBinding); // Put the result in the implicit binding
                              // handle defined in the IDL file.
    
    	if(status)
    	{
    		exit(status);
    	}
    
    	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
    
    	// Free the memory allocated by a string.
    	status = RpcStringFree(&szStringBinding); // String to be freed.
    
    	if(status)
    	{
    		exit(status);
    	}
    
    	// Releases binding handle resources and disconnects from the server.
    	status = RpcBindingFree(
    	&hDoRPCBinding);	// Frees the implicit binding handle defined in
    						// the IDL file.
    
    	if (status)
    	{
    		exit(status);
    	}
    
    	system ("PAUSE");
    
    	return 0;
    }
    
    // Memory allocation function for RPC.
    // The runtime uses these two functions for allocating/deallocating
    // enough memory to pass the string to the server.
    void* __RPC_USER midl_user_allocate(size_t size)
    {
    	return malloc(size);
    }
    
    // Memory deallocation function for RPC.
    void __RPC_USER midl_user_free(void* p)
    {
    	free(p);
    }

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,358

    Re: getting RpcExceptionCode 5 with RPC code

    Well, 5 means ERROR_ACCESS_DENIED - "Access is denied" (or RPC_S_ACCESS_DENIED - "Access for making the remote procedure call was denied")
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2012
    Posts
    99

    Re: getting RpcExceptionCode 5 with RPC code

    ok thanks. how do i fix it? why is the access denied?
    Last edited by beginner91; April 10th, 2013 at 06:49 AM.

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,358

    Re: getting RpcExceptionCode 5 with RPC code

    Quote Originally Posted by beginner91 View Post
    ok thanks. how do i fix it? why is the access denied?
    I don't know!
    I'd trie to disable FireWall. If it would help - then added FireWall exception for the port you are using and, probably, for your exe.
    Victor Nijegorodov

  5. #5
    Join Date
    Mar 2012
    Posts
    99

    Re: getting RpcExceptionCode 5 with RPC code

    i created a client service program before using sockets. i don't understand why access is denied with RPC

  6. #6
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,328

    Re: getting RpcExceptionCode 5 with RPC code

    Code:
    Show(szMsg);
    What is this supposed to do? What rpc functions does it call?
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  7. #7
    Join Date
    Mar 2012
    Posts
    99

    Re: getting RpcExceptionCode 5 with RPC code

    thats a function thats created from the idl file
    Code:
    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
        
    }

  8. #8
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,328

    Re: getting RpcExceptionCode 5 with RPC code

    One of the exceptions that can be raised by NdrConformantStringBufferSize(..), NdrConformantStringMarshall(..) and others is access violation. You'll need to debug the code to find out exactly which function is raising the exception.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  9. #9
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,358

    Re: getting RpcExceptionCode 5 with RPC code

    beginner91!
    Did you debug this code to exactly know which function call causes the exception?
    Victor Nijegorodov

  10. #10
    Join Date
    Mar 2012
    Posts
    99

    Re: getting RpcExceptionCode 5 with RPC code

    yes i did debug it but it didn't bring to a function that causes an exception

  11. #11
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,358

    Re: getting RpcExceptionCode 5 with RPC code

    So, what was the last statement that was executed before the exception?
    Victor Nijegorodov

  12. #12
    Join Date
    Mar 2012
    Posts
    99

    Re: getting RpcExceptionCode 5 with RPC code

    but is there is no exception. it runs through all the code i posted without any problems but there must be something wrong if its going to the RpcExcept function

    i attached the client file
    rpc.zip
    Last edited by beginner91; April 10th, 2013 at 08:42 AM.

  13. #13
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,358

    Re: getting RpcExceptionCode 5 with RPC code

    Quote Originally Posted by beginner91 View Post
    i... when i tried running the server and client i get Runtime exception occured:5
    in the client console
    Quote Originally Posted by beginner91 View Post
    but is there is no exception. it runs through all the code i posted without any problems but there must be something wrong if its going to the RpcExcept function
    Sorry, I cannot get you! Id there some exception or there is not any?
    Victor Nijegorodov

  14. #14
    Join Date
    Mar 2012
    Posts
    99

    Re: getting RpcExceptionCode 5 with RPC code

    there is no exception. the problem is its displaying the line Runtime exception occured:5 from the RpcExcept function
    i attached the code to the previous post

  15. #15
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,358

    Re: getting RpcExceptionCode 5 with RPC code

    Well, it is displaying the line :Runtime exception occured:5" because your code somehow (direct or indirect) calls "the RpcExcept function".
    So set the breakpoint in it, start debugger and when it will break there look at the callstack to see how and where from this function is called.
    Victor Nijegorodov

Page 1 of 3 123 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center