문제

The Direct2D system library provides 4 overloaded versions for the D2D1CreateFactory function. Now suppose I'm loading the Direct2D library dynamically, and obtain the pointer to the CreateFactory function using the GetProcAddress system call. Which of the 4 overloaded functions will be returned? Is there a way to specify explicitly which function I need? Is this a downside of dynamic loading versus static linking, in that some of the overloaded functions will not be accessible?

HMODULE hDllD2D = ::LoadLibraryExA("d2d1.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32);
FARPROC fnCreateFactory = ::GetProcAddress(hDllD2D, "D2D1CreateFactory");
// What should be the call signature of `fnCreateFactory` ?
도움이 되었습니까?

해결책

The function in the DLL is the most general one, D2D1CreateFactory(D2D1_FACTORY_TYPE,REFIID,D2D1_FACTORY_OPTIONS*,void**) function. If you peek inside the declarations in d2d1.h, you'll see that that function is declared, whereas the other overloads are just inline functions in the header which call through to the general function:

#ifndef D2D_USE_C_DEFINITIONS

inline
HRESULT
D2D1CreateFactory(
    __in D2D1_FACTORY_TYPE factoryType,
    __in REFIID riid,
    __out void **factory
    )
{
    return 
        D2D1CreateFactory(
            factoryType,
            riid,
            NULL,
            factory);
}


template<class Factory>
HRESULT
D2D1CreateFactory(
    __in D2D1_FACTORY_TYPE factoryType,
    __out Factory **factory
    )
{
    return
        D2D1CreateFactory(
            factoryType,
            __uuidof(Factory),
            reinterpret_cast<void **>(factory));
}

template<class Factory>
HRESULT
D2D1CreateFactory(
    __in D2D1_FACTORY_TYPE factoryType,
    __in CONST D2D1_FACTORY_OPTIONS &factoryOptions,
    __out Factory **ppFactory
    )
{
    return
        D2D1CreateFactory(
            factoryType,            
            __uuidof(Factory),
            &factoryOptions,
            reinterpret_cast<void **>(ppFactory));
}

#endif // #ifndef D2D_USE_C_DEFINITIONS
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top