-
April 10th, 2013, 06:37 AM
#1
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);
}
-
April 10th, 2013, 06:43 AM
#2
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
-
April 10th, 2013, 06:44 AM
#3
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.
-
April 10th, 2013, 07:19 AM
#4
Re: getting RpcExceptionCode 5 with RPC code
Originally Posted by beginner91
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
-
April 10th, 2013, 07:26 AM
#5
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
-
April 10th, 2013, 07:53 AM
#6
Re: getting RpcExceptionCode 5 with RPC code
What is this supposed to do? What rpc functions does it call?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 10th, 2013, 07:55 AM
#7
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
}
-
April 10th, 2013, 08:10 AM
#8
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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 10th, 2013, 08:10 AM
#9
Re: getting RpcExceptionCode 5 with RPC code
beginner91!
Did you debug this code to exactly know which function call causes the exception?
Victor Nijegorodov
-
April 10th, 2013, 08:21 AM
#10
Re: getting RpcExceptionCode 5 with RPC code
yes i did debug it but it didn't bring to a function that causes an exception
-
April 10th, 2013, 08:24 AM
#11
Re: getting RpcExceptionCode 5 with RPC code
So, what was the last statement that was executed before the exception?
Victor Nijegorodov
-
April 10th, 2013, 08:33 AM
#12
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.
-
April 10th, 2013, 08:41 AM
#13
Re: getting RpcExceptionCode 5 with RPC code
Originally Posted by beginner91
i... when i tried running the server and client i get Runtime exception occured:5
in the client console
Originally Posted by beginner91
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
-
April 10th, 2013, 08:44 AM
#14
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
-
April 10th, 2013, 08:50 AM
#15
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|