2013-04-17 26 views
3

Direct2D系统库为D2D1CreateFactory函数提供了4个重载版本。现在假设我正在动态加载Direct2D库,并使用GetProcAddress系统调用来获取指向CreateFactory函数的指针。 4个重载函数中的哪一个将被返回?有没有一种方法来明确指定我需要的功能?这是动态加载与静态链接的不利之处,因为一些重载函数将无法访问?访问DLL中的重载函数

HMODULE hDllD2D = ::LoadLibraryExA("d2d1.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32); 
FARPROC fnCreateFactory = ::GetProcAddress(hDllD2D, "D2D1CreateFactory"); 
// What should be the call signature of `fnCreateFactory` ? 
+0

DLL功能是通过名字引出/只有序号,没有任何参数信息。因此,DLL不能导出具有相同名称的重载函数。编译器将不得不装饰导出的名称以使它们唯一。当使用'GetProcAddress()'时,你必须指定那些特定的装饰名称,而不是通用名称被重载。 –

回答

5

DLL中的函数是最常用的函数,D2D1CreateFactory(D2D1_FACTORY_TYPE,REFIID,D2D1_FACTORY_OPTIONS*,void**) function。如果你在偷看的d2d1.h里面的声明,你会看到,该函数声明,而其他重载是在头球攻门稍稍内联函数用于通过一般的函数调用:

#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 
+0

必须是html问题,因为这不可能是头文件的样子。 * return D2D1CreateFactory( factoryType, __uuidof(Factory), reinterpret_cast (factory)); *不会编译。期待4个参数。得到3. – thang

+0

@thang:它编译得很好。上面第一个'inline'函数需要3个参数。 –

+0

啊好的电话。没有看到顶部的东西。对于那个很抱歉。 – thang