我想得到程序本身所在的路径,如何做??

解决方案 »

  1.   

    DWORD GetModuleFileName(
      HMODULE hModule,    // handle to module to find filename for
      LPTSTR lpFilename,  // pointer to buffer to receive module path
      DWORD nSize         // size of buffer, in characters
    );
      

  2.   

    int     i;
    char    szPath[256];GetModuleFileName(hInstance,szPath,256);
    i = strlen(szPath);
    while(szPath[i] != '\\')szPath[i --] = '\0';
      

  3.   

    下面这个我用的很多次了。很方便CString AppPath()
    {
    CString sModFileName;
    CString str1;
    GetModuleFileName(NULL, sModFileName.GetBuffer(MAX_PATH), MAX_PATH);
    sModFileName.ReleaseBuffer();
    str1=sModFileName;
    str1.MakeReverse();
    return(sModFileName.Left(sModFileName.GetLength() - str1.Find('\\')));
    }