通常,你在服務程序中調用DLL,而DLL又會加載許多配置和文件,一般會出現DLL加載不到配置和文件,原因是你的服務程序被加載后,路徑并不是你程序的所在目錄,故DLL也不是,因此加載不了。解決辦法,是在DLL的路徑或服務程序中設計當前的工作路徑。
主要函數為:SetCurrentDirectory;
設置當前工作路徑實例如下:
#include <iostream>#include <windows.h>#include <string>using namespace std;int main(){ char buf[1000]; int i=1000; GetCurrentDirectory(1000,buf); //得到當前工作路徑 cout<<buf<<endl; char strModule[256]; GetModuleFileName(NULL,strModule, 256); //得到當前模塊路徑 cout<<strModule<<endl; string a; a.assign(buf); cout<<a<<endl; a.append("http://..//"); //設置為當前工作路徑為當時的上一級 //a=a+"..//"; SetCurrentDirectory(a.c_str()); //設置 GetCurrentDirectory(1000,buf); cout<<buf<<endl; return 0;}以上就是C++中獲取當前工作路徑的代碼,希望大家以后多多支持武林網。
新聞熱點
疑難解答
圖片精選