Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7547983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:35:47+00:00 2026-05-30T09:35:47+00:00

I want to write some unit tests for my COM object using googletest. Unfortunately

  • 0

I want to write some unit tests for my COM object using googletest. Unfortunately I get an exception when CreateInstance is called: 0xC0000005: Access violation reading location 0x00000000.

The code basically looks like this:

MyClass.h

class ATL_NO_VTABLE CMyClass
    : public CComObjectRootEx<CComMultiThreadModel>,
    public CComCoClass<CMyClass, &CLSID_MyClass>,
    public IConnectionPointImpl<CMyClass, &IID_IMyClassListener>,
    public IConnectionPointContainerImpl<CMyClass>,
    public IDispatchImpl<MyComClass, &IID_MyComClass, &LIBID_MyLib, 1, 0>
{
    ...
}

Test.cpp

#include "stdafx.h"
#include "gtest/gtest.h"

#include "MyClass.h"

TEST(MyClassTest, IsCreated)
{
    HRESULT hr(E_FAIL);
    CComPtr<MyComClass> lMyObject;
    hr = CMyClass::CreateInstance(&lMyObject);
    EXPECT_EQ(S_OK, hr);
}

int main(int argc, char **argv)
{
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

I am able to call CreateInstance without any problems in some existing (non-test) projects. I don’t really understand COM/ATL so I’m having trouble figuring out why I’m getting this weird exception.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:35:48+00:00Added an answer on May 30, 2026 at 9:35 am

    @Roman had the right idea. I put the following above main() in my Test.cpp and everything started working:

    #include "resource.h"
    
    const IID LIBID_TestLib = {0xA5AD0596, 0x14AE, 0x43A3, {0xB2, 0x5E, 0xF7, 0xF9, 0x19, 0x93, 0xA7, 0x24}};
    
    class CTestModule : public CAtlExeModuleT<CTestModule>
    {
    
    public:
    
        DECLARE_LIBID(LIBID_TestLib)
        DECLARE_REGISTRY_APPID_RESOURCEID(IDR_TEST, "{575D971E-C35B-470f-BE6B-FFB9145CCCD3}")
    
    };
    
    CTestModule gAtlModule;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some unit tests in UnitTest++ and want to write a bunch of
It has been decided to write some unit tests using moq etc..It's lots of
I'm attempting to write some unit tests using EasyMock and TestNG and have run
I am new to unit testing and I want to write some tests to
I'm trying to write some unit tests for Command object validations. When my command
I want to write some unit tests for an interceptor that intercepts the Loggable
I have some Web API methods that I want to write unit tests for.
I want to write some text directly to a file using Flex 3 /
I am trying to write some unit tests for my MVC3 project (the first
I want to write a few unit tests that do not make any changes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.