Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #1299 > unrolled thread

GetShortPathName

Started by"Paul D B" <polleke@NOMORESPAMhnt.be>
First post2011-06-08 10:27 +0200
Last post2011-06-14 09:21 +0200
Articles 5 — 3 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  GetShortPathName "Paul D B" <polleke@NOMORESPAMhnt.be> - 2011-06-08 10:27 +0200
    Re: GetShortPathName "Gerhard Bunzel" <g.bunzel@domonet.de> - 2011-06-08 11:25 +0200
      Re: GetShortPathName "Paul D B" <polleke@NOMORESPAMhnt.be> - 2011-06-08 13:11 +0200
        Re: GetShortPathName "Uwe Heyer" <uwe.heyer@aristik.de> - 2011-06-08 18:54 +0000
          Re: GetShortPathName "Paul D B" <polleke@NOMORESPAMhnt.be> - 2011-06-14 09:21 +0200

#1299 — GetShortPathName

From"Paul D B" <polleke@NOMORESPAMhnt.be>
Date2011-06-08 10:27 +0200
SubjectGetShortPathName
Message-ID<4def328d$0$14263$ba620e4c@news.skynet.be>
Sorry to bother you with something obvious but those API functions are my 
weak point :-)
I'm a bit confused about this function.

In VO first parameter must be a PTR, second a PSZ
_DLL FUNC GetShortPathName(lpszLongPath AS PTR, lpszShortPath AS PSZ, 
cchBuffer AS DWORD);

AS DWORD PASCAL :KERNEL32.GetShortPathNameA

However Win32 SDK makes me things it is just the other way around?

lpszLongPath

Points to a null-terminated path string. The function obtains the short form 
of this path.

lpszShortPath

Points to a buffer to receive the null-terminated short form of the path 
specified by lpszLongPath.


if someone can clarify this a bit I'd be grateful

Paul 

[toc] | [next] | [standalone]


#1301

From"Gerhard Bunzel" <g.bunzel@domonet.de>
Date2011-06-08 11:25 +0200
Message-ID<isnf6g$ifl$1@news.m-online.net>
In reply to#1299
Paul,

...that should work:


FUNCTION GetShortPath ( cLongName AS STRING ) AS STRING PASCAL
 LOCAL DIM cShortName[512] IS BYTE
 LOCAL dwRet AS DWORD

 dwRet := GetShortPathName( String2Psz(cLongName), @cShortName, 512 )

 IF dwRet == 0 .OR. dwRet == 512 //  Error
  RETURN NULL_STRING
 ENDIF

 RETURN Mem2String(@cShortName, dwRet)



HTH

Gerhard



"Paul D B" <polleke@NOMORESPAMhnt.be> schrieb im Newsbeitrag 
news:4def328d$0$14263$ba620e4c@news.skynet.be...
> Sorry to bother you with something obvious but those API functions are my 
> weak point :-)
> I'm a bit confused about this function.
>
> In VO first parameter must be a PTR, second a PSZ
> _DLL FUNC GetShortPathName(lpszLongPath AS PTR, lpszShortPath AS PSZ, 
> cchBuffer AS DWORD);
>
> AS DWORD PASCAL :KERNEL32.GetShortPathNameA
>
> However Win32 SDK makes me things it is just the other way around?
>
> lpszLongPath
>
> Points to a null-terminated path string. The function obtains the short 
> form of this path.
>
> lpszShortPath
>
> Points to a buffer to receive the null-terminated short form of the path 
> specified by lpszLongPath.
>
>
> if someone can clarify this a bit I'd be grateful
>
> Paul 

[toc] | [prev] | [next] | [standalone]


#1303

From"Paul D B" <polleke@NOMORESPAMhnt.be>
Date2011-06-08 13:11 +0200
Message-ID<4def58c8$0$14247$ba620e4c@news.skynet.be>
In reply to#1301
Hi Gerard,

thanks for the code. But I had got it working by passing in cLongname as a 
PSZ (as you do).
I was however wondering why in VO the function's first parameter is defined 
as a PTR instead of PSZ ??

Paul


"Gerhard Bunzel"  schreef in bericht news:isnf6g$ifl$1@news.m-online.net...

Paul,

...that should work:


FUNCTION GetShortPath ( cLongName AS STRING ) AS STRING PASCAL
LOCAL DIM cShortName[512] IS BYTE
LOCAL dwRet AS DWORD

dwRet := GetShortPathName( String2Psz(cLongName), @cShortName, 512 )

IF dwRet == 0 .OR. dwRet == 512 //  Error
  RETURN NULL_STRING
ENDIF

RETURN Mem2String(@cShortName, dwRet)



HTH

Gerhard



"Paul D B" <polleke@NOMORESPAMhnt.be> schrieb im Newsbeitrag
news:4def328d$0$14263$ba620e4c@news.skynet.be...
> Sorry to bother you with something obvious but those API functions are my 
> weak point :-)
> I'm a bit confused about this function.
>
> In VO first parameter must be a PTR, second a PSZ
> _DLL FUNC GetShortPathName(lpszLongPath AS PTR, lpszShortPath AS PSZ, 
> cchBuffer AS DWORD);
>
> AS DWORD PASCAL :KERNEL32.GetShortPathNameA
>
> However Win32 SDK makes me things it is just the other way around?
>
> lpszLongPath
>
> Points to a null-terminated path string. The function obtains the short 
> form of this path.
>
> lpszShortPath
>
> Points to a buffer to receive the null-terminated short form of the path 
> specified by lpszLongPath.
>
>
> if someone can clarify this a bit I'd be grateful
>
> Paul

[toc] | [prev] | [next] | [standalone]


#1312

From"Uwe Heyer" <uwe.heyer@aristik.de>
Date2011-06-08 18:54 +0000
Message-ID<959uqoFomeU1@mid.individual.net>
In reply to#1303
Paul D B wrote:

> Hi Gerard,
> 
> thanks for the code. But I had got it working by passing in cLongname
> as a PSZ (as you do).  I was however wondering why in VO the
> function's first parameter is defined as a PTR instead of PSZ ??
> 
> Paul
> 
> 
> "Gerhard Bunzel"  schreef in bericht
> news:isnf6g$ifl$1@news.m-online.net...
> 
> Paul,
> 
> ...that should work:
> 
> 
> FUNCTION GetShortPath ( cLongName AS STRING ) AS STRING PASCAL
> LOCAL DIM cShortName[512] IS BYTE
> LOCAL dwRet AS DWORD
> 
> dwRet := GetShortPathName( String2Psz(cLongName), @cShortName, 512 )
> 
> IF dwRet == 0 .OR. dwRet == 512 //  Error
>  RETURN NULL_STRING
> ENDIF
> 
> RETURN Mem2String(@cShortName, dwRet)
> 
> 
> 
> HTH
> 
> Gerhard
> 
> 
> 
> "Paul D B" <polleke@NOMORESPAMhnt.be> schrieb im Newsbeitrag
> news:4def328d$0$14263$ba620e4c@news.skynet.be...
> > Sorry to bother you with something obvious but those API functions
> > are my  weak point :-) I'm a bit confused about this function.
> > 
> > In VO first parameter must be a PTR, second a PSZ
> > _DLL FUNC GetShortPathName(lpszLongPath AS PTR, lpszShortPath AS
> > PSZ,  cchBuffer AS DWORD);
> > 
> > AS DWORD PASCAL :KERNEL32.GetShortPathNameA
> > 
> > However Win32 SDK makes me things it is just the other way around?
> > 
> > lpszLongPath
> > 
> > Points to a null-terminated path string. The function obtains the
> > short  form of this path.
> > 
> > lpszShortPath
> > 
> > Points to a buffer to receive the null-terminated short form of the
> > path  specified by lpszLongPath.
> > 
> > 
> > if someone can clarify this a bit I'd be grateful
> > 
> > Paul

Hi Paul,

psz and ptr both are ptrs. ptrs are equal to dwords (you can use long
in some conditions too)
all are 4 bytes long and from the sight of cpu there are no differences
reading their values and address the right memory.

psz stand for a ptr for some text terminated with 0x00
ptr stand for a ptr for something (void pointer) not terminated with
some token the compiler/api/3P_dll aware of (default).

VO strong typing isn't so strong as in your case the base type is equal
a ptr. If you merge ptr and psz you must know what you are doing. If VO
would stronger type checking you should get a warning that ptr <> psz
and you would cast the argument.
   
eg. memcopy(ptrTarget, ptrSource, size)         // strong
memcopy(ptrTarget, pszSource, size) 			// not so strong
memcopy(ptrTarget, _cast(ptr, pszSource), size) // strong 

as you can see in Gerhard Bunzels code
> dwRet := GetShortPathName( String2Psz(cLongName), @cShortName, 512 )

seeing strong: "@cShortName" is a "byte ptr" and not a psz

see this call as
[on call]
GetShortPathName(ptrTerminated, [in] ptrMaybeTerminated, dwDatasize)
[on return] 
GetShortPathName(ptrTerminated, [out] ptrIsNowTerminated, dwDatasize)

for the record I would declare GetShortPathName(psz, psz, dword)
but technical there is no difference with (ptr, psz, dword)

Hope this is of some help

Ahoj
-Uwe

AFAIK 
String in VO is an ptr too. The Length of valid data is stored on top
of this. [length4Byte]DataString[0x00] // Terminated only for easy use
of pszFamily().


pseudo code 
str = "DataString"
psz = psz(str)
dw  = cast_dword, psz) - sizeof(dword)
? dword(dw) // 10

If you use something like SLen(str) VO looks for the value of
length4Byte
PSZLen(psz(str)) will count until it hit the first 0x00




















-- 

[toc] | [prev] | [next] | [standalone]


#1395

From"Paul D B" <polleke@NOMORESPAMhnt.be>
Date2011-06-14 09:21 +0200
Message-ID<4df70c08$0$14251$ba620e4c@news.skynet.be>
In reply to#1312
Many Thanks Uwe, I will keep your mail as a reference in my 
VO-documentation. Still learning every day!

Paul

Hi Paul,

psz and ptr both are ptrs. ptrs are equal to dwords (you can use long
in some conditions too)
all are 4 bytes long and from the sight of cpu there are no differences
reading their values and address the right memory.

psz stand for a ptr for some text terminated with 0x00
ptr stand for a ptr for something (void pointer) not terminated with
some token the compiler/api/3P_dll aware of (default).

VO strong typing isn't so strong as in your case the base type is equal
a ptr. If you merge ptr and psz you must know what you are doing. If VO
would stronger type checking you should get a warning that ptr <> psz
and you would cast the argument.

eg. memcopy(ptrTarget, ptrSource, size)         // strong
memcopy(ptrTarget, pszSource, size) // not so strong
memcopy(ptrTarget, _cast(ptr, pszSource), size) // strong

as you can see in Gerhard Bunzels code
> dwRet := GetShortPathName( String2Psz(cLongName), @cShortName, 512 )

seeing strong: "@cShortName" is a "byte ptr" and not a psz

see this call as
[on call]
GetShortPathName(ptrTerminated, [in] ptrMaybeTerminated, dwDatasize)
[on return]
GetShortPathName(ptrTerminated, [out] ptrIsNowTerminated, dwDatasize)

for the record I would declare GetShortPathName(psz, psz, dword)
but technical there is no difference with (ptr, psz, dword)

Hope this is of some help

Ahoj
-Uwe

AFAIK
String in VO is an ptr too. The Length of valid data is stored on top
of this. [length4Byte]DataString[0x00] // Terminated only for easy use
of pszFamily().


pseudo code
str = "DataString"
psz = psz(str)
dw  = cast_dword, psz) - sizeof(dword)
? dword(dw) // 10

If you use something like SLen(str) VO looks for the value of
length4Byte
PSZLen(psz(str)) will count until it hit the first 0x00




















--  

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web