-
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.
-
Re: getting RpcExceptionCode 5 with RPC code
now when i try debug at the RpcExcept function it displays a messages saying there is no source code available for the current location
but this only comes up if i put the breakpoint at the RpcExcept. it i put it before this function that that message doesn't display
-
Re: getting RpcExceptionCode 5 with RPC code
Quote:
Originally Posted by
beginner91
now when i try debug at the RpcExcept function it displays a messages saying there is no source code available for the current location
What does call stack window show you?
-
Re: getting RpcExceptionCode 5 with RPC code
ok here is what is in callstack when the breakpoint is on the line with RPCExpect (1)
> DoRPC_Client.exe!@_EH4_CallFilterFunc@8() + 0x12 bytes Asm
DoRPC_Client.exe!_except_handler4(_EXCEPTION_RECORD * ExceptionRecord=0x0012f85c, _EXCEPTION_REGISTRATION_RECORD * EstablisherFrame=0x0012ff24, _CONTEXT * ContextRecord=0x0012f870, void * DispatcherContext=0x0012f830) + 0xb9 bytes C
ntdll.dll!770f7199()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
ntdll.dll!770f716b()
ntdll.dll!770cf98f()
ntdll.dll!770f6ff7()
KernelBase.dll!74bc812f()
KernelBase.dll!74bc812f()
KernelBase.dll!74bc812f()
rpcrt4.dll!74cbbf55()
rpcrt4.dll!74cae106()
rpcrt4.dll!74cae0d1()
rpcrt4.dll!74ca61eb()
DoRPC_Client.exe!Show(const unsigned char * szMsg=0x0012fee4) Line 101 + 0x16 bytes C
DoRPC_Client.exe!main() Line 44 + 0x9 bytes C
DoRPC_Client.exe!__tmainCRTStartup() Line 266 + 0x19 bytes C
DoRPC_Client.exe!mainCRTStartup() Line 182 C
kernel32.dll!74d8ed6c()
ntdll.dll!7711377b()
ntdll.dll!7711374e()
-
Re: getting RpcExceptionCode 5 with RPC code
Quote:
Originally Posted by
beginner91
ok here is what is in callstack when the breakpoint is on the line with RPCExpect (1)
>
Code:
DoRPC_Client.exe!@_EH4_CallFilterFunc@8() + 0x12 bytes Asm
DoRPC_Client.exe!_except_handler4(_EXCEPTION_RECORD * ExceptionRecord=0x0012f85c, _EXCEPTION_REGISTRATION_RECORD * EstablisherFrame=0x0012ff24, _CONTEXT * ContextRecord=0x0012f870, void * DispatcherContext=0x0012f830) + 0xb9 bytes C
ntdll.dll!770f7199()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
ntdll.dll!770f716b()
ntdll.dll!770cf98f()
ntdll.dll!770f6ff7()
KernelBase.dll!74bc812f()
KernelBase.dll!74bc812f()
KernelBase.dll!74bc812f()
rpcrt4.dll!74cbbf55()
rpcrt4.dll!74cae106()
rpcrt4.dll!74cae0d1()
rpcrt4.dll!74ca61eb()
DoRPC_Client.exe!Show(const unsigned char * szMsg=0x0012fee4) Line 101 + 0x16 bytes C
DoRPC_Client.exe!main() Line 44 + 0x9 bytes C
DoRPC_Client.exe!__tmainCRTStartup() Line 266 + 0x19 bytes C
DoRPC_Client.exe!mainCRTStartup() Line 182 C
kernel32.dll!74d8ed6c()
ntdll.dll!7711377b()
ntdll.dll!7711374e()
Well, now it is clear that the last statementof your code that was tried to execute was
Code:
DoRPC_Client.exe!Show(const unsigned char * szMsg=0x0012fee4) Line 101 + 0x16 bytes
- in your Show() function.
So why don't you want to set the breakpoint at the beginning of this function then debug it step-by-step (F10) to exactly know what statement/call causes the exception?
-
1 Attachment(s)
Re: getting RpcExceptionCode 5 with RPC code
ok i attached a screen shot of the error message that came up:
Attachment 31287
also heres what was in the callstack when this message came up
> DoRPC_Client.exe!main() Line 46 + 0x13 bytes C
DoRPC_Client.exe!__tmainCRTStartup() Line 266 + 0x19 bytes C
DoRPC_Client.exe!mainCRTStartup() Line 182 C
kernel32.dll!74d8ed6c()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
ntdll.dll!7711377b()
ntdll.dll!7711374e()
-
Re: getting RpcExceptionCode 5 with RPC code
Then rebuild your project before starting debugger.
-
Re: getting RpcExceptionCode 5 with RPC code
ok it reaches this line in the show function and then jumps out of the function and goes to RpcExcept
Code:
NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR *) _StubMsg.Buffer );
-
Re: getting RpcExceptionCode 5 with RPC code
Good!
Now use Google to search for NdrSendReceive access denied and see how others tried to solve this problem!
-
Re: getting RpcExceptionCode 5 with RPC code
i can't find an answer for this problem
-
Re: getting RpcExceptionCode 5 with RPC code
So no one else had a similar problem?
Or no one could solve such a problem?
Or what?
-
Re: getting RpcExceptionCode 5 with RPC code
no one else had a similar problem. i couldn't find a solution
-
Re: getting RpcExceptionCode 5 with RPC code
In what OS do you have this Access denied exception?
-
Re: getting RpcExceptionCode 5 with RPC code
i'm using a windows 7 computer and visual studio 2008
-
Re: getting RpcExceptionCode 5 with RPC code
could you download the code and try it yourself?
http://www.aspfree.com/c/a/net/intro...indows-part-i/
the link to download the code is in the 3rd paragraph
-
Re: getting RpcExceptionCode 5 with RPC code
And where is this "3rd paragraph"? And where is a link for download?
And why not to ask the author of this code?
-
Re: getting RpcExceptionCode 5 with RPC code
just before the line What is this RPC anyway? there is a link to download the code near the top of the page.
this is an old example and nobody has written to it since 2008 and there is no way to contact the author
this was the easiest example of RPC i could find. there isn't many tutorials
-
Re: getting RpcExceptionCode 5 with RPC code
Well, I tested it and got the same error on my XP SP3. But it was not the NdrSendReceive that caused this error but NdrFreeBuffer
Perhaps, you will try some MSDN samples instead? like this one:
http://msdn.microsoft.com/en-us/libr...(v=VS.60).aspx
-
Re: getting RpcExceptionCode 5 with RPC code
i saw that example before but i don't understand it. it talks about the files being used but there is no link to these files...
-
Re: getting RpcExceptionCode 5 with RPC code
-
Re: getting RpcExceptionCode 5 with RPC code
ok i followed that tutorial and i got this error in the server program:
error C2664: 'RpcServerUseProtseqEpW' : cannot convert parameter 1 from 'unsigned char *' to 'RPC_WSTR'
so i changed this code:
Code:
status = RpcServerUseProtseqEp(
reinterpret_cast<unsigned char*>("ncacn_ip_tcp"),
RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
reinterpret_cast<unsigned char*>("4747"),
NULL);
to this:
Code:
status = RpcServerUseProtseqEp(
L"ncacn_ip_tcp",
RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
L"4747",
NULL);
but now i am getting this error:
error C2664: 'RpcServerUseProtseqEpW' : cannot convert parameter 1 from 'const wchar_t [13]' to 'RPC_WSTR'
-
Re: getting RpcExceptionCode 5 with RPC code
Quote:
Originally Posted by
beginner91
ok i followed that tutorial and i got this error in the server program:
error C2664: 'RpcServerUseProtseqEpW' : cannot convert parameter 1 from 'unsigned char *' to 'RPC_WSTR'
That is because you are building your program as Unicode, not MBCS. You should be using the _T() macro or _TEXT() macro when creating string literals.
Quote:
so i changed this code:
[code] status = RpcServerUseProtseqEp(
reinterpret_cast<unsigned char*>("ncacn_ip_tcp"),
No. Do not do this. The function is expecting 16-bit char strings, and casting one string type to another doesn't do any conversion.
Code:
RpcServerUseProtseqEp(_T("ncacn_ip_tcp"), RPC_C_PROTSEQ_MAX_REQS_DEFAULT, _T("4747"), NULL);
The above code now will compile, regardless if your code is compiled as Unicode or ANSI/MBCS.
Regards,
Paul McKenzie