Link to home
Start Free TrialLog in
Avatar of mohd_maridi
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-00403321bfac),
  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(“ncacn_ip_tcp”, 20, “8000”, NULL);
    RpcServerRegisterIf(hello_v1_0_s_ifspec, 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(NULL, “ncacn_ip_tcp”, argv[1], “8000”, NULL,
&pszStringBinding);
    RpcBindingFromStringBinding(pszStringBinding, &hello_IfHandle);
    if (strcmp(argv[2], “SHUTDOWN”)) HelloProc(argv[2]);
    else Shutdown();
    RpcStringFree(&pszStringBinding);
    RpcBindingFree(&hello_IfHandle);
    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.
Avatar of chensu
chensu
Flag of Canada image

Debug it to see exactly which function causes the GPF.
Avatar of jkr
Hmm, the code seems OK - where does it crash? In the client or in the server? At which line does the crash occur?
Avatar of mohd_maridi
mohd_maridi

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?.

I prefer to send the whole example application to you via e-mail if you mind, may be something wrong in settings.
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.
I found the problem.
ASKER CERTIFIED SOLUTION
Avatar of Mohammed_maridi
Mohammed_maridi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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