Unable to create an instance of CComPtr

0

I am trying to use a simple c++ out of process COM object, SimpleObject, with a console app I am writing using Visual Studio Community 2017 (15.3.5) and Windows 10, but I am unable to initialize my object. I am using an ATL project for SimpleObject with the simple object threading set to Apartment, Aggregation is set to yes, my interface is custom, and Free-threaded marshaller is enabled.

I have registered the SimpleObject dll and exe successfully with the OS, but when I run my app prints to the console indicating that the object was successfully initialized. Debugging shows that My CComPtr is null and gives me the error:

0x80080005: Server execution failed.

My Console App looks like this:

#include "stdafx.h"
#include <atlbase.h>

#include "..\TestCOM\TestCOM_i.h"
#include "..\TestCOM\TestCOM_i.c"

int main(){
    HRESULT hr = CoInitialize(NULL);

    CComPTR<ISimpleObject> testCom;
    hr = testCom.CoCreateInstance(CLSID_SimpleObject, NULL, CLSCTX_ALL);

    if(!FAILED(hr)){
        printf("Created!\n");
        testCom.Release();
    }

    CoUninitialize();

    return 0;
}

My .idl file looks like this:

import "oaidl.idl";
import "ocidl.idl";

[
    object,
    uuid(02f8b163-c674-4f9a-9b8d-d61bb5aca632),
    pointer_default(unique)
]
interface ISimpleObject : IUnknown
{
    HRESULT Hello();
};
[
    uid(ec13d56e-de4f-4d1d-aed0-0f219d95effc),
    version(1.0),
]
library TestCOMLib
{

    [
      uid(74f0adfcc-23ad-47c79a59-591dca8117a1)
    ]
    coclass SimpleObject
    {
        [default] interface ISImpleObject;
    };
};

import"shobjidl.idl";
import"shobjidl.idl";
import"shobjidl.idl";

The only thing that I added was HRESULT Hello();

My SimpleObject.h looks like this:

#pragma once
#include "resource.h"
#include "TestCom_i.h"    
using namespace ATL;

class ATL_NO_VTABLE CSimpleObject :
      public CComObjectRootEx<CComSingleThreadModel>,
      public CComCoClass<CSimpleObject, &CSimpleObject>,
      public ISImpleObject
{
public:
   CSimpleObject()
   {
       m_pkUnkMarshaler = NULL:
   }

DECLARE_REGISTRY_RESOURCEID(106)

BEGIN_COM_MAP(CSImpleObject)
    COM_INTERFACE_ENTRY(ISimpleObject)
    COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pkUnkMarshaler .p)
END_COM_MAP()

   DECLARE_PROTECT_FINAL_CONSTRUCT()
   DECLARE_GET_CONTROLLING_UNKNOWN()

   HRESULT FinalConstruct()
   {
       return COCreateFreeThreadedMarshaler(
           GerControllingUnknown(), &m_pkUnkMarshaler .p);
   }

   void FinalRelease()
   {
       m_pkUnkMarshaler.Release();
   }

   CComPtr<IUnkown> m_pkUnkMarshaler;

public:
    STDMETHOD(Hello)() {retrun S_OK; }
};
OBJECT_ENTRY_AUTO(__uuidof(SimpleObject), CSimpleObject)

The only thing I added was STDMETHOD(Hello)() {retrun S_OK; }

What am I missing? My Console app is based off this example from Microsoft and with the exception of the two added lines in TestCom.idl and SimpleObject.h everything is auto-generated by Visual Studio and the compiler.

c++
visual-studio
com
visual-studio-2017
atl
asked on Stack Overflow Oct 25, 2017 by zzz711

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0