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

Hybrid View

  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
    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.

  4. #4
    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

  5. #5
    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(...)

  6. #6
    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.

  7. #7
    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.

  8. #8
    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

  9. #9
    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?

  10. #10
    Join Date
    Feb 2022
    Posts
    44

    Re: SHCreateDirectory not found

    Quote Originally Posted by existenceproduct View Post
    I am getting this dmvfoam 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?
    no solution to this

  11. #11
    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 existenceproduct View Post
    no solution to this
    There is nothing to solve, since we don't see the code casing the error, nor have we any info about what the error was.
    Victor Nijegorodov

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

    Re: SHCreateDirectory not found

    Please, provide the exact error message together with the error code, as well as some info about your system, like Windows OS, VS OS
    Victor Nijegorodov

  13. #13
    Join Date
    Feb 2022
    Posts
    44

    Re: SHCreateDirectory not found

    Quote Originally Posted by VictorN View Post
    Please, provide the exact error message together with the error code, as well as some info about your system, like Windows OS, VS OS
    i already share the exact code

  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 existenceproduct View Post
    i already share the exact code
    You didn't.
    You only posted the #includes with #pragmas and meaningless description.
    So no code, no exact error message.
    Victor Nijegorodov

  15. #15
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: SHCreateDirectory not found

    Well excluding "format.h", those headers compile fine for me with VS2022.

    But without seeing the code that gives the compiler errors...

    This test code compiles OK with the given header:

    Code:
    int main() {
    	HWND hwnd {};
    	SHCreateDirectory(hwnd, L"path");
    
    }
    Note that the 2nd param is of type PCWSTR ie a wide (unicode) string and not an ASCII one.
    Last edited by 2kaud; July 18th, 2022 at 03:42 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

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