自由空间

free space

  VC知识库BLOG :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 登录 ::
  82 随笔 :: 1 文章 :: 237 评论 :: 0 Trackbacks
<2009年12月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

留言簿(23)

随笔分类

随笔档案

文章档案

相册

vckbase

搜索

最新评论

阅读排行榜

评论排行榜

 typedef int (WINAPI *SHCreateDIR)(HWND hwnd,LPCTSTR pszPath, SECURITY_ATTRIBUTES *psa);
 
 HINSTANCE hmod;
 hmod = ::LoadLibrary ("shell32.dll");
 if(hmod==NULL)
 {
  AfxMessageBox("Fail");
 }
 SHCreateDIR lpproc;
 lpproc = (SHCreateDIR)GetProcAddress (hmod,"SHCreateDirectoryExA");
 if(lpproc!=(SHCreateDIR)NULL)
 {
  if((*lpproc)(NULL,"d:\\test\\bbb\\cc",NULL)==ERROR_SUCCESS )
  {
   AfxMessageBox("ok");
  }
 }
 FreeLibrary(hmod);
posted on 2006-03-09 20:33 自由空间 阅读(3647) 评论(6)  编辑 收藏

评论

# re: 创建多级目录,感谢迷糊提醒。 2006-03-10 09:56 清风雨
这个API是公开的。

没必要运行时加载查询吧?直接编译连接就可以的。

# re: 创建多级目录,感谢迷糊提醒。 2006-03-10 23:19 freedk
我的SDK加载不了。。没办法:P

# re: 创建多级目录,感谢迷糊提醒。 2007-06-22 16:07 winter
这样做很好。静态链接会使程序会变大的。
不是没公开的API,就不能这样用。

# re: 创建多级目录,感谢迷糊提醒。 2008-03-15 22:02 diviner
当然是公开的,查一下msdn就知道了。说加载不了的是这个要可能要定义WIN版本号。

SHCreateDirectoryEx Function

--------------------------------------------------------------------------------

Creates a new file system folder.

Syntax

int SHCreateDirectoryEx(          HWND hwnd,
    LPCTSTR pszPath,
    SECURITY_ATTRIBUTES *psa
);
Parameters

hwnd
[in] Handle to a parent window. This parameter can be set to NULL if no user interface will be displayed.
pszPath
[in] Pointer to a null-terminated string specifying the fully qualified path of the directory. This string is of maximum length of 248 characters, including the terminating null character.
psa
[in] Pointer to a SECURITY_ATTRIBUTES structure with the directory's security attribute. Set this parameter to NULL if no security attributes need to be set.
Return Value

Returns ERROR_SUCCESS if successful. If the operation fails, other error codes can be returned, including those listed here. For values not specifically listed, see System Error Codes.

ERROR_BAD_PATHNAME The pszPath parameter was set to a relative path. 
ERROR_FILENAME_EXCED_RANGE The path pointed to by pszPath is too long. 
ERROR_PATH_NOT_FOUND The system cannot find the path pointed to by pszPath. The path may contain an invalid entry. 
ERROR_FILE_EXISTS The directory exists. 
ERROR_ALREADY_EXISTS The directory exists. 
ERROR_CANCELLED The user canceled the operation. 


Remarks

This function creates a file system folder whose fully qualified path is given by pszPath. If one or more of the intermediate folders do not exist, they will be created as well. SHCreateDirectoryEx also verifies that the files will be visible. If not:


If hwnd is set to a valid window handle, a message box is displayed warning the user that he or she might not be able to access the files. If the user chooses not to proceed, the function returns ERROR_CANCELLED. 
If hwnd is set to NULL, no user interface is displayed and the function returns ERROR_CANCELLED. 

Function Information

Minimum DLL Version shell32.dll version 5.0 or later 
Custom Implementation No 
Header shlobj.h 
Import library shell32.lib 
Minimum operating systems Windows 2000, Windows Millennium Edition 
Unicode Implemented as ANSI and Unicode versions.  



这个函数能大多少啊。静态也没关系,

# re: 创建多级目录,感谢迷糊提醒。 2008-03-27 21:47 h
if((*lpproc)(NULL,"d:\\test\\bbb\\cc",NULL)==ERROR_SUCCESS )

前段时间看到他们讨论函数指针调用时到底是pfn还是(*pfn)的方式,在我的印象中,好像直接是pfn调用为好(好像是标准中是这么说的,你可你在这个BLOG中查找一下)。

# re: 创建多级目录,感谢迷糊提醒。 2009-12-28 10:44 TTDragon
win2000下才可以使用.
楼主的方法不晓得在xp中可行不?

标题  
姓名  
主页
验证码 *
内容   
  登录  使用高级评论  Top
[使用Ctrl+Enter键可以直接提交]