0

I'm trying to teach myself the fundamentals of COM, and to that end I'm following along with Kenny Kerr's "The Essentials of COM" course on Pluralsight. I'm currently stuck in the "Remoting" section of part 2, specifically the video titled "Demo: Defining Remotable Interfaces". My current full solution is listed here: https://github.com/jakotheshadows/COMClient

I get as far as running

midl hen.idl

and then compiling the output from that with

cl /W4 /DWIN32 /DREGISTER_PROXY_DLL *.c /link /DLL rpcrt4.lib /OUT:Proxy.dll /DEF:Exports.def

then I do

regsvr32 Proxy.dll

and it says it successfully registered.

However when I get to the CoGetClassObject call while running the client:

#include "Precompiled.h"
#include "..\COMServer\Server.h"
#include "..\Proxy\Hen.h"

using namespace Microsoft::WRL;

int main()
{
    ComRuntime runtime(Apartment::SingleThreaded);

    ComPtr<IPSFactoryBuffer> proxyFactory;

    HR(CoGetClassObject(__uuidof(IAsyncHenEventHandler), 
                    CLSCTX_INPROC_SERVER,
                    nullptr,
                    __uuidof(proxyFactory), 
                    reinterpret_cast<void**>(proxyFactory.GetAddressOf())));

    ComPtr<IHen> hen;

    HR(CoCreateInstance(__uuidof(Hen), nullptr, CLSCTX_INPROC_SERVER, __uuidof(hen), reinterpret_cast<void**>(hen.GetAddressOf())));

    hen->Cluck();
}

I get an error and I can see that CoGetClassObject returns HRESULT REGDB_E_CLASSNOTREG, and Kenny Kerr's example seems to "just work".

Update: It has been suggested that the rclsid and the riid arguments are backwards in the call shown above. I have tried:

HR(CoGetClassObject(_uuidof(proxyFactory),
                    CLSCTX_INPROC_SERVER,
                    nullptr,
                    __uuidof(IAsyncHenEventHandler),
                    reinterpret_cast<void**>(proxyFactory.GetAddressOf())));

And I still run into the same HRESULT from CoGetClassObject.

I'm not sure where I've gone wrong here. I am noticing that I see something different when I check Proxy.dll with the dependency walker than Mr. Kerr gets when he does it:

enter image description here

Most notably, in my Proxy.dll there is this "ADVAPI32.DLL" that is not present when Kenny Kerr inspects Proxy.dll with depends.exe. Also, I see a few errors that he doesn't seem to get:

  1. Warning: At least one delay-load dependency module was not found.
  2. Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

Another difference between my environment and Kenny Kerr's is that I'm using Visual Studio 2015, where he is using Visual Studio 2012. I'm running in Windows 7 Professional x64.

Jakotheshadows
  • 1,485
  • 2
  • 13
  • 24
  • 1
    It is pretty unclear why you make that CoGetClassObject() call at all, it doesn't do anything useful. You seem to have reversed the *rclsid* and *riid* arguments. – Hans Passant Apr 29 '16 at 18:17
  • I think the point of this part of the tutorial is just to see that what we did beforehand made that call possible, and that it returned success (S_OK). I'm really green at this right now, so it is difficult for me to understand / answer why the instructor chose to do this. If you could please point me towards anything that might alleviate my ignorance I'll happily read ^_^ – Jakotheshadows Apr 29 '16 at 18:39
  • 1
    The first parameter to CoGetClassObject must be a CLSID - the id of a class instance. You are passing __uuidof(IBlahblah) - which will be an Interface ID. If "Hen" is the object that implements IAsyncHenEventHandler, then you want to pass __uuidof(Hen) to CoGetClassObject. – Chris Becke Apr 29 '16 at 18:53
  • So what I'm hearing is that the _uuidof(proxyFactory) and _uuidof(IAsyncHenEventHandler) are backwards. I've tried switching them around and get the same error. At this point I'm thinking that there is something left out of this section of the tutorial as it was deemed to obvious to include. I'm also a bit confused as to why the the instructor chose to make this call with the arguments backwards like that, and why it "worked" for him (worked, as in he got an S_OK from the COM call to CoGetClassObject). – Jakotheshadows Apr 29 '16 at 19:06

0 Answers0