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.
mohd_maridiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
Debug it to see exactly which function causes the GPF.
0
jkrCommented:
Hmm, the code seems OK - where does it crash? In the client or in the server? At which line does the crash occur?
0
mohd_maridiAuthor Commented:
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?.

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

mohd_maridiAuthor Commented:
I prefer to send the whole example application to you via e-mail if you mind, may be something wrong in settings.
0
mohd_maridiAuthor Commented:
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.
0
Mohammed_maridiCommented:
I found the problem.
0
Mohammed_maridiCommented:
thank you.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
graberCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.