1. David Pylatuk
  2. PowerBuilder
  3. Thursday, 9 May 2024 14:33 PM UTC

Has anyone successfully called this API from PowerBuilder? I have found two different declarations online as follows:

Try 1

Long ll_null
Any la_null
SetNull(ll_null)
SetNull(la_null)

FUNCTION long SHCreateDirectoryEx(Long hwnd, String pszPath, Any psa) LIBRARY "shell32.dll" ALIAS FOR "SHCreateDirectoryExA"

SHCreateDirectoryEx(ll_null, ls_message_log_dir, la_null)

Try 2

FUNCTION ulong SHCreateDirectoryEx (REF string lpDirectory, ulong lpSecurityAttributes) LIBRARY "shell32.dll" ALIAS FOR "SHCreateDirectoryExA"

ls_directory = "C:\Your\Directory\Path"
lul_result = SHCreateDirectoryEx(ls_directory, 0)

 

Both return errors on the call, any help would be appreciated. Thanks.

 

Francisco Martinez @Appeon Accepted Answer Pending Moderation
  1. Thursday, 9 May 2024 14:41 PM UTC
  2. PowerBuilder
  3. # 1

The only reference I can find to a function named similarly to what you wrote is this: https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shcreatedirectoryexw

The name is a little different (a W at the end) could this be the cause of the problem?

 

Regards,
Francisco

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 9 May 2024 14:55 PM UTC
  2. PowerBuilder
  3. # 2

Hi David:

  Is there a reason that your not using the built-in PB CreateDirectory() command instead?

https://docs.appeon.com/pb2022r3/powerscript_reference/createDirectory_func.html

Regards ... Chris 

Comment
There are no comments made yet.
David Pylatuk Accepted Answer Pending Moderation
  1. Thursday, 9 May 2024 15:05 PM UTC
  2. PowerBuilder
  3. # 3

Hi Chris,

I was trying but could not get it to work, it was always returning an error of -1.

I am trying to create a long path with multiple folders that may not already exist, my understanding is that the built in PowerBuilder function only creates one folder at a time.

ie. I am trying to create a folder like:

 

c:\a\b\c\d\e\f

And do not want to have to loop through the required path to see if each folder exists.

 

Comment
  1. Chris Pollach @Appeon
  2. Thursday, 9 May 2024 16:38 PM UTC
Hi David;

For the built-in method, you need to handle this type of nested directory creation (or long as you put it) in a loop.

Regards .. Chris
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Thursday, 9 May 2024 15:43 PM UTC
  2. PowerBuilder
  3. # 4

Hi, David -

This external function declaration should work (although I have not tried it):

FUNCTION Longptr SHCreateDirectoryExW ( &
   Longptr hWnd, &
   String  pszPath, &
   Longptr psa &
   ) LIBRARY "shell32.dll"

Use zero for the first and last argument values.

If successful, the API function issues a return code of zero (the value of the ERROR_SUCCESS #define value in the Windows API). Other possible return code values from this Windows API function:

ERROR_SUCCESS              = 0
ERROR_BAD_PATHNAME         = 161
ERROR_FILENAME_EXCED_RANGE = 206 // Incorrectly spelled, I know...)
ERROR_PATH_NOT_FOUND       = 3
ERROR_FILE_EXISTS          = 80
ERROR_ALREADY_EXISTS       = 183
ERROR_CANCELLED            = 1223

By the way, the "W" suffix on the API function names designate the Unicode ("W" for "Wide", I believe) version of the API function. The "A" suffix designates the ANSI version. Since PB uses Unicode internally, you should always try to use the Unicode version of API functions whenever possible so that PB does not have to convert argument values to ANSI before calling the external function, then back to Unicode after the external function returns. Good luck.

Best regards, John

Comment
There are no comments made yet.
David Pylatuk Accepted Answer Pending Moderation
  1. Thursday, 9 May 2024 16:08 PM UTC
  2. PowerBuilder
  3. # 5

Thanks very much John,

 

I had the function declaration incorrect... yours worked and the long directory structure gets created properly..

 

Much appreciated.

Comment
  1. Miguel Leeuwe
  2. Thursday, 9 May 2024 20:14 PM UTC
Please mark as "resolved"
  1. Helpful
There are no comments made yet.
David Pylatuk Accepted Answer Pending Moderation
  1. Thursday, 9 May 2024 17:14 PM UTC
  2. PowerBuilder
  3. # 6

Understood. Thanks Chris.

I did this:

 

Declare this external function:

FUNCTION Longptr SHCreateDirectoryExW ( Longptr hWnd, String pszPath, Longptr psa ) LIBRARY "shell32.dll"

And make this call:

SHCreateDirectoryExW(0, ls_message_log_dir, 0)

 

This call returns zero (0) if successfull

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.