自由空间
free space
<2008年3月>
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345

留言簿(22)

随笔分类

随笔档案

文章档案

相册

vckbase

搜索

最新评论

阅读排行榜

评论排行榜

 
VC知识库BLOG   首页  新随笔  联系  聚合  登录 
  随笔-81 文章-1 评论-227 Trackbacks-0
 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 自由空间 阅读(2888) 评论(5)  编辑 收藏
Comments
  • # re: 创建多级目录,感谢迷糊提醒。
    清风雨
    Posted @ 2006-03-10 09:56
    这个API是公开的。

    没必要运行时加载查询吧?直接编译连接就可以的。
  • # re: 创建多级目录,感谢迷糊提醒。
    freedk
    Posted @ 2006-03-10 23:19
    我的SDK加载不了。。没办法:P
  • # re: 创建多级目录,感谢迷糊提醒。
    winter
    Posted @ 2007-06-22 16:07
    这样做很好。静态链接会使程序会变大的。
    不是没公开的API,就不能这样用。
  • # re: 创建多级目录,感谢迷糊提醒。
    diviner
    Posted @ 2008-03-15 22:02
    当然是公开的,查一下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: 创建多级目录,感谢迷糊提醒。
    h
    Posted @ 2008-03-27 21:47
    if((*lpproc)(NULL,"d:\\test\\bbb\\cc",NULL)==ERROR_SUCCESS )

    前段时间看到他们讨论函数指针调用时到底是pfn还是(*pfn)的方式,在我的印象中,好像直接是pfn调用为好(好像是标准中是这么说的,你可你在这个BLOG中查找一下)。
标题  
姓名  
主页
验证码 *
内容   
  登录  使用高级评论  Top
[使用Ctrl+Enter键可以直接提交]