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);
}
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")
Re: getting RpcExceptionCode 5 with RPC code
ok thanks. how do i fix it? why is the access denied?
Re: getting RpcExceptionCode 5 with RPC code
Quote:
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.
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
Re: getting RpcExceptionCode 5 with RPC code
What is this supposed to do? What rpc functions does it call?
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
}
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.
Re: getting RpcExceptionCode 5 with RPC code
beginner91!
Did you debug this code to exactly know which function call causes the exception?
Re: getting RpcExceptionCode 5 with RPC code
yes i did debug it but it didn't bring to a function that causes an exception
Re: getting RpcExceptionCode 5 with RPC code
So, what was the last statement that was executed before the exception?
1 Attachment(s)
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
Attachment 31285
Re: getting RpcExceptionCode 5 with RPC code
Quote:
Originally Posted by
beginner91
i... when i tried running the server and client i get Runtime exception occured:5
in the client console
Quote:
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?
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
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.