zoukankan      html  css  js  c++  java
  • Windows API GetShortPathName GetLongPathName

    函数原型:

    The GetShortPathName function retrieves the short path form of a specified input path.

    DWORD GetShortPathName(
                                                    LPCTSTR lpszLongPath,  // null-terminated path string
                                                    LPTSTR lpszShortPath,  // short form buffer
                                                    DWORD cchBuffer        // size of short form buffer,in TCHARs
                                                   );

    The GetLongPathName function converts the specified path to its long form. If no long path is found, this function simply returns the specified name.
    DWORD GetLongPathName(
                                                    LPCTSTR lpszShortPath, // file name
                                                    LPTSTR lpszLongPath,   // path buffer
                                                    DWORD cchBuffer        // size of path buffer,in TCHARs
                                                  );

    说明:
    这两个函数是用来把传入的路径转换为相对应的长路径或者短路径的,传入的路径要必须存在,否则会转换失败。
    写一个程序事例:

    int _tmain(int argc, _TCHAR* argv[])
    {
    	WCHAR szShort[MAX_PATH] = { 0 };
    	WCHAR szFullPath[MAX_PATH] = TEXT("D:\桌面\MP3\英语\hommesick.mp3");
    	DWORD dwShortBytes = GetShortPathName(szFullPath, szShort, MAX_PATH);
    
    	WCHAR wszLongPath[MAX_PATH] = { 0 };
    	DWORD dwLongBytes = GetLongPathName(szShort, wszLongPath, MAX_PATH);
    
    	WCHAR szPath[MAX_PATH] = { 0 };
    	GetModuleFileName(NULL, szPath, MAX_PATH);
    
    	WCHAR wszLong[MAX_PATH] = { 0 };
    	DWORD dwLong = GetLongPathName(szPath, wszLong, MAX_PATH);
    
    }
    

     结果:
    Windows API   GetShortPathName   GetLongPathName - Prairie - work labor and play

    分析:
    可见szShort被转化为短格式的路径,还可以得出并不是所有的路径都可以被转化的,传入的路径本身已经为长路径或者短路径 ,而调用GetLongPathName或者GetShortPathName的话,则不会转换

  • 相关阅读:
    调整心态,夯实基础
    js实现轮播图动画(更新"旋转木马")
    封装简单动画函数-由简到完善
    纯Css绘制三角形箭头三种方法
    JS实现图片''推拉门''效果
    一个基于 canvas 的画板
    Python 控制台进度条的实现
    Flask博客开发——Tinymce编辑器
    Flask博客开发——登录验证码
    用于水和水蒸汽物性计算的Python模块——iapws
  • 原文地址:https://www.cnblogs.com/priarieNew/p/9756150.html
Copyright © 2011-2022 走看看