1
votes

The following mwe is basically extracted from this example. The full example compiles and works fine, however my mwe does not compile with Visual Studio 2013 and I don't see why not.

#include <dwrite_2.h>
#include <atlbase.h>

using namespace std;


void main()
{
    IDWriteFactory2* m_spdwriteFactory;

    DWriteCreateFactory(
    DWRITE_FACTORY_TYPE_SHARED,
    __uuidof( IDWriteFactory2 ),
    &( m_spdwriteFactory )
    );
}

The error message reads:

------ Build started: Project: Test, Configuration: Debug x64 ------

1> Source.cpp

1>Source.cpp(16): error C2664: 'HRESULT DWriteCreateFactory(DWRITE_FACTORY_TYPE,const IID &,IUnknown **)' : cannot convert argument 3 from 'IDWriteFactory2 **' to 'IUnknown **'

1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

1
The sample code uses the WRL::ComPtr<> smart pointer template class. Which is highly recommended when you write code like this, it takes care of a lot of the boring and error-prone plumbing code you'd have to write when you use the interface pointer directly. Including the (void**) cast you have to use to convince the compiler that you know what you are doing. And the memory leak you created in your snippet by forgetting to call Release(). - Hans Passant
If you formulate your comment into an answer I would accept it as it states the problem and a solution. - NOhs

1 Answers

0
votes

You need to cast m_spdwriteFactory to an IUnknown** to fix the compile error. See the example here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd368040(v=vs.85).aspx