2013-04-17 23 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