Looks like the trailing nulls are being removed auto"magically", so you can
omit

SET VAR guserdesktop = (SGET(.strpath, ((SLOC(.strpath, (CHAR(0)))) - 1),
1))   

I don't know when that happened, but when I wrote it, the string that was
full of nulls still had trailing nulls.. 

:) 

Seriously, it did..

> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Doug
> Hamilton
> Sent: Friday, July 25, 2014 1:00 PM
> To: RBASE-L Mailing List
> Subject: [RBASE-L] - Path of User's Desktop
> 
> Back Jan '11, Mike Byerley posted a small RBase routine using stdcall
> to get the path to the user's desktop.
> It has worked flawlessly until I did some testing yesterday on a
> routine that uses Mike's code.  The entire code is below for context,
> but the specific command where the path is lost is:
> SET VAR gUserDeskTop = (SGET(.strpath, ((SLOC(.strpath, (CHAR(0)))) -
> 1), 1))
> 
> Variable strpath is predefined as 260 null characters.
> The correct path is returned in the variable strpath; the SGET's
> purpose is extract just the path from the 260 characters (path + nulls)
> that was returned by the dlcall.
> However, it appears that strpath is already trimmed of trailing nulls -
> or any other characters that I've tried predefining in strpath.  Hence
> the SLOC chokes and gUserDeskTop that is returned is blank.
> So I guess the question is: Are trailing characters automatically
> trimmed in the dlcall?
> Is this a fluke on my system or a permanent update for which I should
> remove the SGET command?
> Is this a change in a Win 7 update or an RBase update?
> I've scanned 4 What's New in R:Base looking for "trim" and "trail" but
> couldn't find any relevant references.
> 
> RBase 9.5.4.30717 (32)
> Win 7, SP1
> 
> Just wondering what the best course of action should be.
> TIA,
> Doug
> 
> --UserDesktop.RMD  get full path to user's desktop --Courtesy Mike
> Beyerly, 01/13/11 {demo of SHGetSpecialFolderPath function mbyerley
> 6/1/2008 }
> 
> SET VAR max_path INTEGER = 260
> SET VAR lngfolderfound INTEGER = NULL
> SET VAR strpath TEXT = NULL
> SET VAR gUserDeskTop TEXT = NULL
> IF (chkfunc('SHGetSpecialFolderPathA')) = 0 THEN
>   STDCALL function 'SHGetSpecialFolderPathA' alias
> 'SHGetSpecialFolderPath' +
>    (integer, integer, ptr text (260), integer) : integer ENDIF
> 
> SET VAR lngfolder = 16
> { Set the variable as a BUFFER of MAX_PATH Characters filled with
> Nulls.  The
>   VAR is passed by Reference and is filled with the PATH in the
> function.  When
>   VARs are created this way, you can't trim the length, so we look for
> the first
>   NULL (Char(0)) in the returned value and SGET everything up to that
> value
>   to COPY to the VAR specfolder.  As Simple as that.  If you wanted to
> Create the
>   Special Folder if it is NOT FOUND, you would change the first 0 in
> the DLCALL
>   argument to a NON ZERO value.
> }
> 
> -- CREATE the BUFFER of length max_path for SET VAR strpath =
> (SFIL((CHAR(0)), .max_path))
> 
> SET VAR lngfolderfound = +
>   (dlcall('Shell32','SHGetSpecialFolderPathA', 0, lngfolder, strpath,
> 0))
> 
> IF lngfolderfound > 0 THEN
>   -- The strpath var has to be SGET to omit the trailing nulls from the
> BUFFER
>   SET VAR gUserDeskTop = (SGET(.strpath, ((SLOC(.strpath, (CHAR(0)))) -
> 1), 1)) ENDIF
> 
> CLEAR VAR  +
>  lngfolder, +
>  lngfolderfound, +
>  max_path, +
>  strpath
> 
> RETURN
> 
> 
> 
> ________________________________
> 
>  <http://www.avast.com/>      This email is free from viruses and
> malware because avast! Antivirus <http://www.avast.com/>  protection is
> active.
> 


Reply via email to