XiaoHui.net 笑汇程序员论坛首页
工作并快乐着,职业并休闲着
寻梦的岁月从不言辛苦几许,
不问收获几多……
» 游客:  申请新用户 | 登录 | 会员 | 统计 | 帮助 » XiaoHui.Net 笑汇程序员论坛 | 纯文字版 | 全站索引 | XiaoHui.com


[其他] 获得自身路径的函数是什么?

RSS 订阅当前论坛  

上一主题 下一主题
     

标题: [其他] 获得自身路径的函数是什么?  
 
ljjweichang
小水手
Rank: 1



UID 29776
精华 0
积分 10
帖子 10
阅读权限 10
注册 2007-3-13
状态 离线
获得自身路径的函数是什么?

辉哥,获得自身路径的函数是什么?得到WINDOWS 的长文件名后有什么函数可以转成短文件名吗?WINDOWS 的短文件名格式怎么转成长文件名呢?谢谢!
2007-3-13 11:41#1
查看资料  Blog  发短消息  顶部
 
XiaoHui
管理员
Rank: 9Rank: 9Rank: 9


UID 2
精华 1
积分 4861
帖子 4851
阅读权限 200
注册 2001-1-23
来自 猎户星座
状态 离线
1. 获取自身运行的路径:

GetModuleFileName
The GetModuleFileName function retrieves the fully qualified path for the specified module.

To specify the process that contains the module, use the GetModuleFileNameEx function.

DWORD GetModuleFileName(
  HMODULE hModule,    // handle to module
  LPTSTR lpFilename,  // path buffer
  DWORD nSize         // size of buffer
);
hMoudle 为应用程序的句柄. 如果是 MFC 程序, 可以这样写:

TCHAR t_tcaPath[MAX_PATH];
GetModuleFileName( AfxGetInstanceHandle(), t_tcaPath, MAX_PATH);


飞往猎户星座....
2007-3-13 16:28#2
查看资料  访问主页  Blog  发短消息  顶部
 
XiaoHui
管理员
Rank: 9Rank: 9Rank: 9


UID 2
精华 1
积分 4861
帖子 4851
阅读权限 200
注册 2001-1-23
来自 猎户星座
状态 离线
长文件名转成短文件名, 调用 GetShortPathName 函数:

GetShortPathName
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
);
Parameters
lpszLongPath
[in] Pointer to a null-terminated path string. The function retrieves the short form of this path.
Windows NT/2000/XP: In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to nearly 32,000 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see File Name Conventions.

Windows 95/98/Me: This string must not exceed MAX_PATH characters.

lpszShortPath
[out] Pointer to a buffer to receive the null-terminated short form of the path specified by lpszLongPath.
cchBuffer
[in] Specifies the size, in TCHARs, of the buffer pointed to by lpszShortPath.
短的转成长的文件名, 调用 GetLongPathName

GetLongPathName
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
);
Parameters
lpszShortPath
[in] Pointer to a null-terminated path to be converted.
Windows 2000/XP: In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to nearly 32,000 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see File Name Conventions.

Windows 98/Me: This string must not exceed MAX_PATH characters.

lpszLongPath
[out] Pointer to the buffer to receive the long path. You can use the same buffer you used for the lpszShortPath parameter.
cchBuffer
[in] Specifies the size of the buffer, in TCHARs.


飞往猎户星座....
2007-3-13 16:31#3
查看资料  访问主页  Blog  发短消息  顶部
 
ljjweichang
小水手
Rank: 1



UID 29776
精华 0
积分 10
帖子 10
阅读权限 10
注册 2007-3-13
状态 离线
好的,搞定了,谢谢辉哥哦
2007-3-13 16:39#4
查看资料  Blog  发短消息  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题  


 


所有时间为 GMT+8, 现在时间是 2008-12-2 02:42 Powered by Discuz! 4.1.0 清除 Cookies - XiaoHui.Net 笑汇程序员论坛 - Archiver