0

I have a class whose definition is as follows.

class SampleClass: public IDispatchImpl<Interface1, &__uuidof(Interface1)>,
                   public IDispatchImpl<Interface2, &__uuidof(Interface2)>,
                   public IDispatchImpl<Interface3, &__uuidof(Interface3)>,
                   public CComObjectRootEx<CComSingleThreadModel>
        {
            BEGIN_COM_MAP(SampleClass)
                COM_INTERFACE_ENTRY(Interface1)
                COM_INTERFACE_ENTRY(Interface2)
                COM_INTERFACE_ENTRY(Interface3)
                COM_INTERFACE_ENTRY2(IDispatch, Interface1)
            END_COM_MAP()
            ..............................
            ..............................
        }

And this is how I'm instantiating my class.

CComObject<SampleClass> *t;
CComObject<SampleClass>::CreateInstance(&t);

The above code is throwing a null pointer exception @ the line shown below.(From "atlcom.h" file).

template <class Base>
class CComObject : 
public Base
{
    public:
       typedef Base _BaseClass;
       CComObject(_In_opt_ void* = NULL) throw()
       {
           _pAtlModule->Lock();     //_pAtlModule is NULL,and hence NULL pointer exception  is thrown
       }
       ..............................
       ..............................
}

I think there is some problem with the definition of the SampleClass. Can anyone help me to figure it out? Thanks in advance..

Brahmaprasad R
  • 131
  • 2
  • 9
  • I'm simply trying to create an instance of the class, and the code is going to exception. I don't have much information on this. In the same way, I could create instance of another class and the only difference that I could see between these two classes is that, first one implements 3 interfaces and the other one is implementing only one interface. – Brahmaprasad R Jun 29 '15 at 07:03
  • Can you provide the `CreateInstance(&t)` implementation? – krizajb Jun 29 '15 at 07:06
  • 2
    @krizajb its part of ATL. This looks like the CComModule derivative isn't setup properly, and there are, unfortunately, a near-infinite way of *not* doing something correctly, especially in ATL. – WhozCraig Jun 29 '15 at 07:07
  • As I mentioned in my above comment, for a class which is implementing only one interface, I'm not seeing any issue. But here, the class is implementing more than one interface. Also the above code is working prefectly in VS2013. The problem, right now I'm talking about is seen with VS2010. – Brahmaprasad R Jun 29 '15 at 07:13
  • @BrahmaprasadR (1) which version of Visual Studio are you building this with? (2) does your main module properly declare+define a `CComModule` or one of its derivatives correctly? – WhozCraig Jun 29 '15 at 07:16
  • @ WhozCraig, (1) I'm using VS2010, (2)Yeah it does. – Brahmaprasad R Jun 29 '15 at 07:24
  • Ok so next question, do you have a `OBJECT_ENTRY_AUTO` after your class. its important as well. Your setup looks correct, so something else must be missing. And here's the stupid-question: If you open your project settings, on the Configuration/General tab, is "Use of ATL" properly set to whatever flavor of ATL you're desiring (dynamic or static)? – WhozCraig Jun 29 '15 at 07:33
  • Actually the class in question is a mock class which I'm creating for the purpose of a unit test. So OBJECT_ENTRY_AUTO is not accepting the class as a valid input. Also I tried with both static and dynamic values for the Use of ATL setting. But it didn't help. – Brahmaprasad R Jun 29 '15 at 08:36
  • 1
    This seems to be a duplicate of http://stackoverflow.com/questions/33099122/patlmodule-pointer-is-null-when-i-try-to-createinstance-using-the-ccomobject-fu – Fredrik Orderud Jan 31 '16 at 20:11

0 Answers0