2009-06-13 97 views
2

如何獲取模塊路徑?wxWidgets:獲取應用程序路徑

我正在寫擴展名,並附在一個DLL中,並希望在運行時獲得我的庫的路徑。

更新

當然第一種方式工作得很好

static wxString GetModulePath() 
{ 
    static wxString path; 

    WCHAR buf[512] = {0}; 
    GetModuleFileName(NULL, buf, 511); 
    path = buf; 

    return wxPathOnly(path); 
} 

但最後我用第二個

wxStandardPaths sp; 
wxLogError(sp.GetPluginsDir()); 
+0

我只是在尋找'正確','跨平臺'的方式 – jonny 2009-06-13 18:03:20

+0

既然你已經接受了第一個答案,我對你真正想要實現的東西有點困惑:從宿主應用程序中獲取擴展的位置?一旦它被加載,從它自己獲取擴展模塊的位置?如果跨平臺,爲什麼接受與Windows API函數的答案? – mghie 2009-06-13 18:32:28

+0

從它自己獲取擴展模塊的位置,一旦它被加載。 – jonny 2009-06-13 18:47:19

回答

0

這不是wxWidgets的具體結束。 Windows有一個名爲GetModuleFileName的功能,它可以滿足您的需求。鏈接到msdn頁面。

3

我用

#include "wx/stdpaths.h" 
    #include "dialogsApp.h" 
    #include "dialogsMain.h" 

    IMPLEMENT_APP(dialogsApp); 

    bool dialogsApp::OnInit() 
    { 

     wxString xpath; 
     xpath = wxStandardPaths::Get().GetExecutablePath(); 

,似乎工作。