ocx 和 EXE 當前路徑運行路徑區別

獲取工程運行路徑源代碼

string GetProgramDir()     
{      
    char exeFullPath[MAX_PATH]; // Full path   
    string strPath = "";   

    GetModuleFileName(NULL,exeFullPath,MAX_PATH);  
    strPath=(string)exeFullPath;    // Get full path of the file   
    int pos = strPath.find_last_of('\\', strPath.length());   
    return strPath.substr(0, pos);  // Return the directory without the file name   

} 

執行結果:
ocx:會是IE路徑安裝路徑 ocx 和 EXE 當前路徑運行路徑區別

EXE:exe所在文件夾 ocx 和 EXE 當前路徑運行路徑區別

獲取工程當前路徑源代碼

string GetCurrentDir(const string &path){
    string ls_FileName;
    LPTSTR lpBuffer;
    UINT uSize;
    HANDLE hHeap;
    uSize=(GetCurrentDirectory(0,NULL))*sizeof(TCHAR);
    hHeap=GetProcessHeap();
    lpBuffer=(LPSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,uSize);
    GetCurrentDirectory(uSize,lpBuffer);
        ls_FileName = (string) lpBuffer;
    ls_FileName.append(path);
    return ls_FileName;
}

執行結果:
ocx:會是用戶桌面 ocx 和 EXE 當前路徑運行路徑區別

EXE:運行該exe工程的文件夾路徑 ocx 和 EXE 當前路徑運行路徑區別

debug:ocx 和 EXE 當前路徑運行路徑區別(工程名AAA)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章