2

I'm trying to use Windows RPC for communcation between two processes (C/C++, 32bit, Win7).

I've followed the example here Instruction to RPC and successfully got RPC to work. Now I have difficulties getting the proxy / stub thing to work too.

The IDL file looks like this:

[ uuid(3cb112c0-688a-4611-83b6-31d33d87ea28), object ]
interface IDemo : IUnknown
{
    HRESULT ThisIsAMethod([in, string] const char* test);
}

[ uuid(60ad6a21-ba49-483a-b0a2-faa5187b8299), version(1.0),
  implicit_handle(handle_t hDemoBinding)]
interface IDemoRPC
{
    void SimpleTest();
    void GetDemo([out] IDemo** service);
    void Shutdown();
}

I can invoke SimpleTest() remotely on the server from the client. Works just fine. But GetDemo() gives me an access violation when the server 'returns' something else than NULL.

Here's what I've done:

  • Build a DLL based on the generated demo_i.c, demo_p.c, dlldata.c. With REGISTER_PROXY_DLL set and a def file containing the five private entries. I've registered it with regsvr32 (the one from WOW64).

  • Created a DemoImpl class in the server process that extends IDemo and implements ThisIsAMethod as well as AddRef and friends.

  • Implemented GetDemo(IDemo** service) with a one-liner *service = new DemoImpl();

When I invoke GetDemo from the client process, the server process terminates with an access violation (0x00000014). The stacktrace shows that it happens in a separate thread deep within rpcrt4.

I would have expected that the thing returns a proxy to the client.

I have the suspicion that I'm doing something fundamentally wrong here. For one thing, I can't find an example where instances of interface-objects are created with new. There always some some magic with CoGetClassObject or something. No clue how these functions should know where to find the implementation.

Stefan
  • 4,187
  • 1
  • 32
  • 38
  • @noxmetus no I don't. I just implemented DemoImpl it as a straight forward c++ class. – Stefan Aug 06 '16 at 00:02
  • How does the implementation of `IDemoRPC` itself get instantiated? I wonder if the methods of IDemoRPC shouldn't return `HRESULT`. What's the initial ref count of `DemoImpl` when you pass it out of `GetDemo()`? – asynchronos Aug 08 '16 at 18:16
  • IDemoRPC does not have object semantics (notice the absence of the "object" attribute). It cannot be instantiated. It is not a COM thing at all, therefore no refcount and no HRESULT requirement. – Stefan Aug 08 '16 at 19:17
  • Ah. Creating and connecting a COM object via plain RPC is something I'd never heard of. Is that really supported? Perhaps there's no COM infrastructure involved (and it should be). Where is your access violation -- in the client or server? Perhaps RPC is simply copying the pointer value, rather than establishing proxy/stub for marshalling. And the pointer is of course invalid in the client address space. – asynchronos Aug 11 '16 at 17:56
  • I think the normal way to do this is the server would register a COM class factory with associated CLSID, and the client would use e.g. [CoCreateInstance()](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686615%28v=vs.85%29.aspx) to get a proxy to an instance of the thing created by the factory, i.e. the IDemo (Impl). Yes, the class factory and the thing it creates can be instantiated with `new`. – asynchronos Aug 11 '16 at 18:00

0 Answers0