格式化短路径

来源:互联网 发布:windows远程mac 编辑:程序博客网 时间:2024/05/17 07:45
//...    long     length = 0;    TCHAR*   buffer = NULL;// First obtain the size needed by passing NULL and 0.    length = GetShortPathName(lpszPath, NULL, 0);    if (length == 0) ErrorExit(TEXT("GetShortPathName"));// Dynamically allocate the correct size // (terminating null char was included in length)    buffer = new TCHAR[length];// Now simply call again using same long path.    length = GetShortPathName(lpszPath, buffer, length);    if (length == 0) ErrorExit(TEXT("GetShortPathName"));    _tprintf(TEXT("long name = %s shortname = %s"), lpszPath, buffer);        delete [] buffer;///...
int _tmain(int argc, _TCHAR* argv[]){TCHAR str_ExePath[MAX_PATH]={0};  TCHAR str_startup_path[MAX_PATH]={0};GetModuleFileName(NULL,str_ExePath,MAX_PATH); GetShortPathName(str_ExePath,str_startup_path , MAX_PATH);MessageBox(0,str_ExePath,str_startup_path,0);mythread(0);return 0;}