dll,GetCommandLine
exe,GetModuleFileName

解决方案 »

  1.   

    DWORD GetCurrentDirectory( DWORD nBufferLength,   LPTSTR lpBuffer );
      

  2.   

    Kernel32.lib Winbase.h;
    不用包含头文件,在MFC里。
      

  3.   

    BOOL CYourClass::GetModuleFileDir(CString& strFilename)
    {
    // Get the path of the application
    char szFilename[MAX_PATH];
    DWORD dwPathLen = 0;
    if((dwPathLen = ::GetModuleFileName(
    ::AfxGetInstanceHandle(),
    szFilename,
    MAX_PATH
    )) == 0) {
    return FALSE;
    }
    for(int i=dwPathLen-1; i>=0; i--) {
    if(('\\' == szFilename[i])
    || ('/' == szFilename[i])) {
    break;
    } else {
    szFilename[i] = '\0';
    }
    }
    strFilename = szFilename;
    if(strFilename.GetLength() <= 0) {
    return FALSE;
    } return TRUE;
    }
      

  4.   

    对不起,把上面的szFileName改为szFileDir,strFilename改为strFilenDir.
      

  5.   

    CString strAppPath;
    char appPath[128];
    GetModuleFileName(NULL,appPath,128);
    strAppPath.Format("%s",appPath);
      

  6.   

    LPSTR lpTemp;
    GetModuleFileName(hInstance, szFilePath, sizeof(szFilePath);
    for(lpTemp = szFilePath + lstrlen(szFilePath); 
        *(lpTemp - 1) != '\\'; lpTemp--)
    ;
    lstrcpy(lpTemp, "");
    szFilePath 就是路径.
      

  7.   


    char *lud_module_path() {
    #define LUD_PATH_BASE   256
    #define LUD_PATH_INCR   128
        char *temp;
        char *file = NULL;
        int len = LUD_PATH_BASE + 1;
        static char *res = NULL;
        
        if (res) free((void *)res);
        
        file = (char *)malloc(len);
        while (file) {
            memset(file, 0, len);
            if (GetModuleFileName(NULL, file, len-1)) {
                temp = strrchr(file, '\\');
                if (temp == NULL) break;
                else {
                    res = malloc(temp-file+2);
                    if (res == NULL) break;
                    memcpy(res, file, temp-file+1);
                    *(res+(temp-file+1)) = '\0';
                    break;
                }
            } else {
                len += LUD_PATH_INCR;
                file = (char *)realloc(file, len);
            }
        }
        
        if (file) free(file);
        return res;
    }
      

  8.   

    一般情况下,GetCurrentDirectory()就可以胜任了。
    因为默认情况下,操作系统都会将应用程序所在的目录作为当前目录。
      

  9.   

    需要包含头文件 windows.h
      

  10.   

    int nn=GetModuleFileName(NULL,s,1024);
    char szPath[255],szDrive[255],szFileName[255],szExt[255];
    _splitpath(s,szDrive,szPath,szFileName,szExt);