wxWidgets:获取应用程序路径

问题描述:

如何获取模块路径?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

查看wxStandardPaths类。对于你的问题,可以使用GetExecutablePath()GetPluginsDir()方法 - 我只是不确定你想要做什么。

这不是wxWidgets的具体结束。 Windows有一个名为GetModuleFileName的功能,它可以满足您的需求。链接到msdn页面。

我用

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

    IMPLEMENT_APP(dialogsApp); 

    bool dialogsApp::OnInit() 
    { 

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

,似乎工作。