mohd_maridi
asked on
RPC
hi all;
I have read the book titled as Visual c++5 Unleashed and have the following problem in RPC-example mentioned there.
Here is the example...
Listing 44.3. The Interface Definition Language File.
[
uuid (6fdd2ce0-0985-11cf-87c3-0 0403321bfa c),
version(1.0)
]
interface hello
{
void HelloProc([in, string] const unsigned char *pszString);
void Shutdown(void);
}
Listing 44.4. The Application Configuration File.
[
implicit_handle(handle_t hello_IfHandle)
]
interface hello
{
}
The two files, hello.idl and hello.acf, can be compiled by the MIDL compiler using a single command:
midl hello.idl
The result of the compilation is three files produced by the MIDL compiler: hello_c.c, hello_s.c, and hello.h. The files hello_c.c and hello_s.c provide the client- and server-side implementation of stub functions; the hello.h header provides necessary declarations.
Listing 44.5. A simple RPC server.
#include <stdlib.h>
#include <stdio.h>
#include “hello.h”
void HelloProc(const unsigned char *pszString)
{
printf(“%s\n”, pszString);
}
void Shutdown(void)
{
RpcMgmtStopServerListening (NULL);
RpcServerUnregisterIf(NULL , NULL, FALSE);
}
void main(int argc, char * argv[])
{
RpcServerUseProtseqEp(“nca cn_ip_tcp” , 20, “8000”, NULL);
RpcServerRegisterIf(hello_ v1_0_s_ifs pec, NULL, NULL);
RpcServerListen(1, 20, FALSE);
}
void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
{
return(malloc(len));
}
void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
{
free(ptr);
}
Listing 44.6. A simple RPC client.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include “hello.h”
void main(int argc, char *argv[])
{
unsigned char *pszStringBinding;
if (argc != 3)
{
printf(“Usage: %s hostname string-to-print\n”, argv[0]);
exit(1);
}
RpcStringBindingCompose(NU LL, “ncacn_ip_tcp”, argv[1], “8000”, NULL,
&pszStringBinding);
RpcBindingFromStringBindin g(pszStrin gBinding, &hello_IfHandle);
if (strcmp(argv[2], “SHUTDOWN”)) HelloProc(argv[2]);
else Shutdown();
RpcStringFree(&pszStringBi nding);
RpcBindingFree(&hello_IfHa ndle);
exit(0);
}
void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
{
return(malloc(len));
}
void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
{
free(ptr);
}
The client application can be compiled using the following command line:
cl helloc.c hello_c.c rpcrt4.lib
After you have compiled both the server and the client executables, you can test the two programs from two DOS windows. After you start the server in one of the windows, run the client in the other window as follows:
helloc localhost “Hello, World!”
To shut down the server from the client side, type
helloc localhost SHUTDOWN
After coding all the above, every thing compiled with no errors and the server application is now running and waiting for requests, but when running the client application it causes a GPF for both win95 and WinNT.
what do you think the problem is.
I have read the book titled as Visual c++5 Unleashed and have the following problem in RPC-example mentioned there.
Here is the example...
Listing 44.3. The Interface Definition Language File.
[
uuid (6fdd2ce0-0985-11cf-87c3-0
version(1.0)
]
interface hello
{
void HelloProc([in, string] const unsigned char *pszString);
void Shutdown(void);
}
Listing 44.4. The Application Configuration File.
[
implicit_handle(handle_t hello_IfHandle)
]
interface hello
{
}
The two files, hello.idl and hello.acf, can be compiled by the MIDL compiler using a single command:
midl hello.idl
The result of the compilation is three files produced by the MIDL compiler: hello_c.c, hello_s.c, and hello.h. The files hello_c.c and hello_s.c provide the client- and server-side implementation of stub functions; the hello.h header provides necessary declarations.
Listing 44.5. A simple RPC server.
#include <stdlib.h>
#include <stdio.h>
#include “hello.h”
void HelloProc(const unsigned char *pszString)
{
printf(“%s\n”, pszString);
}
void Shutdown(void)
{
RpcMgmtStopServerListening
RpcServerUnregisterIf(NULL
}
void main(int argc, char * argv[])
{
RpcServerUseProtseqEp(“nca
RpcServerRegisterIf(hello_
RpcServerListen(1, 20, FALSE);
}
void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
{
return(malloc(len));
}
void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
{
free(ptr);
}
Listing 44.6. A simple RPC client.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include “hello.h”
void main(int argc, char *argv[])
{
unsigned char *pszStringBinding;
if (argc != 3)
{
printf(“Usage: %s hostname string-to-print\n”, argv[0]);
exit(1);
}
RpcStringBindingCompose(NU
&pszStringBinding);
RpcBindingFromStringBindin
if (strcmp(argv[2], “SHUTDOWN”)) HelloProc(argv[2]);
else Shutdown();
RpcStringFree(&pszStringBi
RpcBindingFree(&hello_IfHa
exit(0);
}
void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
{
return(malloc(len));
}
void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
{
free(ptr);
}
The client application can be compiled using the following command line:
cl helloc.c hello_c.c rpcrt4.lib
After you have compiled both the server and the client executables, you can test the two programs from two DOS windows. After you start the server in one of the windows, run the client in the other window as follows:
helloc localhost “Hello, World!”
To shut down the server from the client side, type
helloc localhost SHUTDOWN
After coding all the above, every thing compiled with no errors and the server application is now running and waiting for requests, but when running the client application it causes a GPF for both win95 and WinNT.
what do you think the problem is.
Debug it to see exactly which function causes the GPF.
Hmm, the code seems OK - where does it crash? In the client or in the server? At which line does the crash occur?
ASKER
The GPF is located at the client stub.
exactly at this call NdrNsGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg, _StubMsg.BufferLength, hello__MIDL_AutoBindHandle );
can you try it?.
exactly at this call NdrNsGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg, _StubMsg.BufferLength, hello__MIDL_AutoBindHandle
can you try it?.
ASKER
I prefer to send the whole example application to you via e-mail if you mind, may be something wrong in settings.
ASKER
I prefer to send you the whole example application via e-mail, if you mind.
It may be something wrong in settings of the project.
It may be something wrong in settings of the project.
I found the problem.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I know it is rather late and I don't know if anyone is still around in regard to this question but could you post the solution that was found. The topic interests me. Thanks
Gregg
Gregg