RPC and C++ ??? 
Author Message
 RPC and C++ ???

Hi !

I would like to write WINDOWS NT 4.0 services
using Visual C++ 5.0.
I will be using C++, according to the fact that I
will also be using MFC.
My services should be able to communicate with
each other via RPC.
I understand that RPC/MIDL is just using plain
C-functions within
the RPC-mechanism.

I would like to know how to use RPC with my C++
obejcts ?!
For example, can I make methods of my objects
available to be called via RPC
instead of plain-C-functions ???

Any help with this would be greatly appreciated
!!!

Many thanks in advance,
Bye Hans Pesata



Mon, 31 Jul 2000 03:00:00 GMT  
 RPC and C++ ???

The short answer is that you must write C wrapper functions for your C++ member
Function(s)

The Long answer :

A better way to look at RPC from a C++ perspective is that an object is defined
in terms of its state ( ie data members ) and actions (ie function members ).
To view RPC in an object oriented aspect, each interface  is an object where
the interface file ( idl file ) specifies the member function(s) and the you
can use context handles to store the state of each instance of the object..
This is case NT Service mechanism will create new instances of the object for
each client connection.

Granted there is no polymorphism, per-se.

Perhaps you should look into DCOM.



Mon, 31 Jul 2000 03:00:00 GMT  
 RPC and C++ ???

Why use RPC????????   Use COM instead.  COM will do all the drudgery work of
RPC for you!


Quote:
>Hi !

>I would like to write WINDOWS NT 4.0 services
>using VISUAL C++ 5.0.
>I will be using C++, according to the fact that I
>will also be using MFC.
>My services should be able to communicate with
>each other via RPC.
>I understand that RPC/MIDL is just using plain
>C-functions within
>the RPC-mechanism.

>I would like to know how to use RPC with my C++
>obejcts ?!
>For example, can I make methods of my objects
>available to be called via RPC
>instead of plain-C-functions ???

>Any help with this would be greatly appreciated
>!!!

>Many thanks in advance,
>Bye Hans Pesata



Mon, 31 Jul 2000 03:00:00 GMT  
 RPC and C++ ???

Hi Patrick !

Thanx for your reply!

Quote:

> The short answer is that you must write C wrapper functions for your C++ member
> Function(s)

Here is what I understand what I have to do:

On the client:

Call a RPC-C-Function from within a member of one of my objects.

That means, the the RPC-C-functions have to be visible (scope)
to my objects.

On the server:

Call the member of one of my objects from within a RPC-C-function.

That means, the objects I create have to be visible (scope)
to the RPC-C-functions.

How can I accomplish this ?
I suppose I have to rename the RPC-C-stub-files to .CPP-files ?!

Quote:
> Perhaps you should look into DCOM.

I suppose this would be the way, but I dont think I have
the time to learn ALL this new stuff with my deadlines.

Bye,
Hans Pesata



Tue, 01 Aug 2000 03:00:00 GMT  
 RPC and C++ ???

Quote:
>Here is what I understand what I have to do:

>On the client:

>Call a RPC-C-Function from within a member of one of my objects.

>That means, the the RPC-C-functions have to be visible (scope)
>to my objects.

Yes.

Quote:
>On the server:

>Call the member of one of my objects from within a RPC-C-function.

>That means, the objects I create have to be visible (scope)
>to the RPC-C-functions.

Yes.

Quote:

>How can I accomplish this ?

See below.

Quote:
>I suppose I have to rename the RPC-C-stub-files to .CPP-files ?!

No.

Okay The catch is that the objects on the server and the objects on the client
are not one and the same.
You should have a client-side class and a server-side class. I hope this is
clear, I am afraid I really
can't explain it without blathering on for pages .. bottomline remember the
reason you are using
object orientation in the first place.

Pseudo Code :

The midl compiler that compiles the idl file creates a idl_file.h

// MyServer.h
class MyServer
{
   int RealFunc( int x );   // this is the real function that does the real
work, and runs on the server

Quote:
};

// RPC_FUNC.h
int REALmy_rpc_func( int x );

// RPC_FUNC.cpp
#include "idl_file.h"
#include "RPC_FUNC.h"
#include "MyServer.h"
int REALmy_rpc_func( int x )
{
     // may be using a global instance of object, or a global list of objects,
     // or maybe object passed as parameter ... here I just declare local
instance
    MyServer     object;

   return object.RealFunc(x);

Quote:
}

All the above files are compiled and linked into the server exe that runs on
the server machine.

All the below files are compiled and linked into the client exe that runs on
the client machine.

// MyClient.h
class MyClient
{
   void do_something();
   // client specific stuff

Quote:
};

// MyClient.cpp
#include "MyClient.h"
#include "idl_file.h"

void MyClient::do_something()
{
    // stuff here ...

    // make call to server
   result = my_rpc_func(25); // note my_rpc_func declared in idl_file.h by midl
compiler versus REALmy_rpc_func
                                                 // which is the real rpc
function that gets called on the server machine

    // do more stuff here

Quote:
}

Hope this helps ... Dave


Tue, 01 Aug 2000 03:00:00 GMT  
 RPC and C++ ???

Hi Dave !

Thanx again for your reply!

Quote:
> Okay The catch is that the objects on the server and the objects on the client
> are not one and the same.
> You should have a client-side class and a server-side class. I hope this is
> clear

Yup. I tried it and it seems to work.
I thought there might be some problems by mixing C and C++ code
and the RPC-stuff.
Maybe the (real) problems start, when I start to use MFC
within my C++/RPC-objects ;-)

Bye,
Hans



Wed, 02 Aug 2000 03:00:00 GMT  
 RPC and C++ ???

Hans,

The basic question when using rpc to remote C++ methods is how to remote

the this pointer.  The canonical way to do this is to use context
handles.  On the client side the context handle is an opaque value
(traditionally a void pointer, but perhaps better an __int64 today).  On

the server side, the context handle may represent anything you want so
long as it provides a means of retrieving the this pointer on the server

side.  For many objects, the context handle may be identical to the this

pointer.  Your interface should provide a method that permits context
binding.  This will be the first method called on the interface.
Another method should be provided to permit disconnection from the
context.  This will be the last method called.  You should also take a
look at the online help under the keys "wire_marshal" and "user_marshal"

since these will allow you to remote language specific types by value.

-regards,
George

Quote:

> Hi !

> I would like to write WINDOWS NT 4.0 services
> using VISUAL C++ 5.0.
> I will be using C++, according to the fact that I
> will also be using MFC.
> My services should be able to communicate with
> each other via RPC.
> I understand that RPC/MIDL is just using plain
> C-functions within
> the RPC-mechanism.

> I would like to know how to use RPC with my C++
> obejcts ?!
> For example, can I make methods of my objects
> available to be called via RPC
> instead of plain-C-functions ???

> Any help with this would be greatly appreciated
> !!!

> Many thanks in advance,
> Bye Hans Pesata



Wed, 02 Aug 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. RPC services without binding to RPC Bind/PortMap?

2. RPC - I need help getting started with RPC

3. Java RPC : ONC RPC In Java - index.html (0/1)

4. rpc from Visual C++ to Unix

5. RPC support for C++

6. How do I install and use RPC calls in MS Visual C++ version 5 MFC

7. Can RPC Server connect to same RPC Server functions?

8. Help Request - Using ONC (SUN) RPC on Win98

9. RPC with HTTP Tunneling

10. Q: assign port to rpc server (no rpcbind called)

11. Simple RPC examples?

12. rpc problem

 

 
Powered by phpBB® Forum Software