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:
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:
- Warning: At least one delay-load dependency module was not found.
- 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.