2013-02-05 13 views
1

我想用微軟鏈接器手動從我的目標文件中導出函數。 當我使用的參數爲這樣的每一個功能,它工作正常:如何使用微軟鏈接器/導出參數

/Export:ExportedFunction1$qqsv /Export:ExportedFunction2$qqsv and so on... 

然後連接器自動正確分配ORDS。然而,在導出表的實際工作中的出口名稱爲「ExportedFunction1$qqsv/ExportedFunction2$qqsv/etc..」 我試過參數做這樣的:

/Export:ExportedFunction1$qqsv,1,ExportedFunction1 /Export:ExportedFunction2$qqsv,2,ExportedFunction2 

但我認爲我使用的參數錯誤?如何正確使用/ Export參數爲導出分配我自己的名稱?

PS: 我使用的是Microsoft(R)增量鏈接器版本7.00.9210

+1

你讀過docs at [MSDN](http://msdn.microsoft.com/en-us/library/7k30y2k5.aspx)? –

+0

是的,但我找不到任何東西。 –

+0

對不起,它看起來我錯過了這個問題..你想重命名一個導出的函數或更改序號嗎? –

回答

1

這裏是DEF文件的樣品溶液。

DLL項目:

CppLib.h:

#ifdef CPPLIB_EXPORTS 
#define CPPLIB_API __declspec(dllexport) 
#else 
#define CPPLIB_API __declspec(dllimport) 
#endif 

CPPLIB_API double MyFunction1(double); 

CppLib.cpp:

CPPLIB_API double MyFunction1(double dd) 
{ 
    return dd; 
} 

CppLib.def:

LIBRARY 

EXPORTS 
MySuperFunction=MyFunction1 @1 

生成DLL。

如果我們在CppLib.DLL運行DUMPBIN,我們會得到:

... 
    ordinal hint RVA  name 

      2 0 0001101E [email protected]@[email protected] = @ILT+25([email protected]@[email protected]) 
      1 1 0001101E MySuperFunction = @ILT+25([email protected]@[email protected]) 
... 

使用CppLib.dll 控制檯應用程序:

#include "CppLib.h" 

#include <Windows.h> 
#include <iostream> 

int main() 
{ 
    typedef double(*MY_SUPER_FUNC)(double); 

    HMODULE hm = LoadLibraryW(L"CppLib.dll"); 
    MY_SUPER_FUNC fn1 = (MY_SUPER_FUNC)GetProcAddress(hm, "MySuperFunction"); // find by name 
    MY_SUPER_FUNC fn2 = (MY_SUPER_FUNC)GetProcAddress(hm, MAKEINTRESOURCEA(1)); // find by ordinal 

    std::cout << fn1(34.5) << std::endl; // prints 34.5 
    std::cout << fn2(12.3) << std::endl; // prints 12.3 

    return 0; 
} 
+0

多數民衆贊成在我正在尋找!非常感謝你!它只是'MySuperFunction = MyFunction1 @ 1' –

+1

@Benjamin Weiss不客氣!如果你願意,你可以省略設置序號_ @ 1_。 –