1. Kwadwo Boahene
  2. PowerBuilder
  3. Thursday, 7 September 2017 15:19 PM UTC

 

I added the Windows API  code below to my production PB 12.1 and Powerbuilder 2017 test applications (same exe)  and this is crashing my app. The crash happens on Windows Server 2012 R2 but fine on my desktop- (Windows 7). Does anyone have an API or anything else that will work in both areas to pull the users person folder information. I using that folder to temporary write some files. PB 2017 trial had more problems because I could never debug with out randomly optimizing some pbls.

 ///////

API

///global external function

Function long SHGetFolderPath ( long hwndOwner, long nFolder, long hToken, long dwFlags, Ref string pszPath ) Library "shell32.dll" alias For "SHGetFolderPathW"

//// local area

Constant Long CSIDL_PERSONAL = 5 // current user My Documents  
Constant Long CSIDL_APPDATA = 26 // current user Application Data  
Constant Long CSIDL_LOCAL_APPDATA = 28 // local settings Application Data  
Constant Long CSIDL_COMMON_DOCUMENTS = 46 // all users My Documents  
Constant Long CSIDL_COMMON_APPDATA = 35 // all users Application Data  
string ls_path  
ulong lul_handle, lul_rc, lul_hToken  
//  
ls_path = Space(256)  
lul_handle = Handle(This)  
SetNull(lul_hToken)  
lul_rc = SHGetFolderPath(lul_handle,  CSIDL_PERSONAL, lul_hToken, 0, gs_personal_folder)  
//  

  gs_personal_folder = gs_personal_folder+"\"
//  

KB

Roland Smith Accepted Answer Pending Moderation
  1. Thursday, 10 October 2019 00:31 AM UTC
  2. PowerBuilder
  3. # 1
Comment
There are no comments made yet.
Leandro Espino Accepted Answer Pending Moderation
  1. Wednesday, 9 October 2019 21:26 PM UTC
  2. PowerBuilder
  3. # 2

I fixed it with this code

  1. function ulong SHGetFolderPath(ulong hwndOwner, long nFolder, &  
  2. ulong hToken, long dwFlags, Ref string pszPath) library 'shell32.dll' &  
  3. alias For "SHGetFolderPathA;Ansi"  
  4.   
  5. or  
  6.   
  7. Function long SHGetFolderPath ( long hwndOwner, long nFolder, &  
  8. long hToken, long dwFlags, Ref string pszPath ) Library "shell32.dll" &  
  9. alias For "SHGetFolderPathW"  
  10.   
  11. Constant Long CSIDL_PERSONAL = 5 // current user My Documents  
  12. Constant Long CSIDL_APPDATA = 26 // current user Application Data  
  13. Constant Long CSIDL_LOCAL_APPDATA = 28 // local settings Application Data  
  14. Constant Long CSIDL_COMMON_DOCUMENTS = 46 // all users My Documents  
  15. Constant Long CSIDL_COMMON_APPDATA = 35 // all users Application Data  
  16. string ls_path  
  17. ulong lul_handle, lul_rc, lul_hToken  
  18.   
  19. ls_path = Space(256)  
  20. lul_handle = Handle(This)  
  21. SetNull(lul_hToken)  
  22. lul_rc = SHGetFolderPath(lul_handle, CSIDL_APPDATA, lul_hToken, 0, ls_path)  
  23.   
  24. RETURN ls_path // path  

 

 

References
  1. http://anvil-of-time.com/wordpress/powerbuilder/powerbuilder-finding-special-folders/
Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 7 September 2017 15:35 PM UTC
  2. PowerBuilder
  3. # 3

Hi Kwadwo;

  FWIW: Your declarations look correct to me.

 

Can you try instead ....

lul_rc = SHGetFolderPath ( 0,  CSIDL_PERSONAL, 0, 0, gs_personal_folder)  

 

HTH

Regards ... Chris

Comment
  1. Kwadwo Boahene
  2. Thursday, 7 September 2017 17:43 PM UTC
Finally, got it working by making the function a local external function instead of global. I don't know why but it works fine.



Thanks,



Kwadwo Boahene



 

  1. Helpful
  1. Michael Kramer
  2. Wednesday, 9 October 2019 22:26 PM UTC
Hey Kwadwo, I always create façade NVO for any external function call.

HTH /Michael

Longer description >>> I *NEVER* declare GLOBAL external functions; NEVER!

Instead I always declare them LOCAL PRIVATE in an NVO that wraps the external calls. One public of_xxx function may contain whole series of external calls, pre-allocate space for REF parameters, catch exceptions, map data values in enums back and forth; and so on.

No matter how complex external functionality I may need, I want the rest of my PB app to look like it is just calling any normal NVO containing any ordinary PowerScript code.
  1. Helpful
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.