CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    SHCreateDirectory not found

    Hi,

    I want to use SHCreateDirectory to create a directory, line C:\D1\D2\D3, etc. but I cannot find it. The compiler gives me the undeclared indentifier (C2065) error. According to MSDN:
    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
    My shell32.dll version is 6.0.2800.1106, I am running on WinXP, with VisualC++ 6.0, SP6, and of course I include shlobj.h. But the funny thing is that there is no SHCreateDirectory in that header. I searched all the headers on my PC and there is not such method.

    What is this?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  2. #2
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: SHCreateDirectory not found

    I think there isn't. Try SHCreateDirectoryEx
    Har Har

  3. #3
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537

    Re: SHCreateDirectory not found

    Download the latest Platfrom SDK from msdn.microsoft.com

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: SHCreateDirectory not found

    Quote Originally Posted by PadexArt
    I think there isn't. Try SHCreateDirectoryEx
    So is the case of SHCreateDirectoryEx... What did you think?
    I was hoping to avoid downloading from Microsoft after I saw yesterday "I, Robot".
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: SHCreateDirectory not found

    Quote Originally Posted by cilu
    So is the case of SHCreateDirectoryEx... What did you think?
    True. I've just checked it and it is missing too. I've pointed it out as SHCreateDirectory doesn't even show up in MSDN Oct 2001.
    Har Har

  6. #6
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537

    Re: SHCreateDirectory not found

    Quote Originally Posted by cilu
    So is the case of SHCreateDirectoryEx... What did you think?
    I was hoping to avoid downloading from Microsoft after I saw yesterday "I, Robot".
    Then forward declare it and use LoadLibrary(...)/GetProcAddress(...)

  7. #7
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: SHCreateDirectory not found

    Quote Originally Posted by Mick
    Then forward declare it and use LoadLibrary(...)/GetProcAddress(...)
    Well Mick, now you're coming with something... Thanks. I will do that.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  8. #8
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    still not working

    I did this:
    Code:
    typedef int (WINAPI* lpfnSHCreateDirectory)( HWND hwnd, LPCWSTR pszPath );
    
    void Tests() 
    {
    	HMODULE hShell32Dll = ::LoadLibrary( _T("shell32.dll") );
    	
    	lpfnSHCreateDirectory lpFn = NULL;
    	if( hShell32Dll )
    	{
    		lpFn  = (lpfnSHCreateDirectory)GetProcAddress( hShell32Dll, "SHCreateDirectory" );
    		if ( lpFn )
    		{
    			int ret = lpFn( NULL, (LPCWSTR)"C:\\D1\\D2\\D3");
    			switch(ret)
    			{
    			case ERROR_BAD_PATHNAME :
    				TRACE("The pszPath parameter was set to a relative path.\n");
    				break;
    			case ERROR_FILENAME_EXCED_RANGE :
    				TRACE("The path pointed to by pszPath is too long. \n");
    				break;
    			case ERROR_FILE_EXISTS :
    				TRACE("The directory exists. \n");
    				break;
    			case ERROR_ALREADY_EXISTS :
    				TRACE("The directory exists. \n");
    				break;
    			case ERROR_CANCELLED :
    			default:
    					TRACE("unknown\n");
    					break;
    			}
    		}
    	}
    	
    	if(	hShell32Dll != (HMODULE)INVALID_HANDLE_VALUE )
    		FreeLibrary(hShell32Dll);
    }
    But it gives me ERROR_BAD_PATHNAME, saying that "The pszPath parameter was set to a relative path". I also tried with a simple "C:\\D1" and it returning the same error... And I don't figure out why...
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  9. #9
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537

    Re: SHCreateDirectory not found

    (LPCWSTR)L"C:\\D1\\D2\\D3"

  10. #10
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: SHCreateDirectory not found

    Yeah... forgot about it... Thanks again, Mick.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  11. #11
    Join Date
    Jul 2005
    Posts
    12

    Re: SHCreateDirectory not found

    I had the same issue with ERROR_BAD_PATHNAME, and this thread fixed it, but I am curious... what does the L in the following line do? Why was it so important?

    Code:
    (LPCWSTR)L"C:\\D1\\D2\\D3"

  12. #12
    Join Date
    May 2005
    Posts
    4,954

    Re: SHCreateDirectory not found

    Quote Originally Posted by esandegren
    I had the same issue with ERROR_BAD_PATHNAME, and this thread fixed it, but I am curious... what does the L in the following line do? Why was it so important?


    Code:
    (LPCWSTR)L"C:\\D1\\D2\\D3"
    that means that it will call the SHCreateDirectoryW api (the unicode one) and not the SHCreateDirectoryA (which is the ascii one)

    Cheers

  13. #13
    Join Date
    Jul 2022
    Posts
    6

    Re: SHCreateDirectory not found

    Quote Originally Posted by golanshahar View Post
    that means that it will call the SHCreateDirectoryW api (the unicode one) and not the SHCreateDirectoryA (which is the ascii one)

    Cheers
    Point of Order...

    It's actually ANSI not ASCII. I know I'm late to this again.

  14. #14
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: SHCreateDirectory not found

    Quote Originally Posted by TheMickSter View Post
    ... I know I'm late to this again.
    Exactly! About 17 years too late...
    Victor Nijegorodov

  15. #15
    Join Date
    Feb 2022
    Posts
    44

    Re: SHCreateDirectory not found

    I am getting this error when I compile my code.

    I had already included the function SHGetFolderPath

    sucessfully, but when I added SHCreateDirectory(NULL, p_path)

    it stopped compiling. I have the following headers

    #include <windows.h>

    #include <stdlib.h>

    #include <malloc.h>

    #include <memory.h>

    #include <tchar.h>

    #include "Format.h"

    #include <wchar.h>

    #include <stdio.h>

    #include <shlwapi.h> // for SHGetFolderPath function

    #include <shlobj.h> // for SHGetFolderPath and SHCreateDirectory function

    //*************************************************************************************************************************

    #pragma comment(lib, "shlwapi")

    #pragma comment(lib, "shell32")

    Any suggestions?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured