Page 1 of 1

GetFullPathName_() - PB bug?

Posted: Sun Oct 28, 2018 7:46 pm
by jassing
The code below is old code I've used in the past.
With pb 5.46 (86/64) it works. 5.62 & 5.70b2 it does not.

Any ideas on if there's something I'm doing wrong, or is it a PB issue? (and is there any way around it?)

Code: Select all

;DWORD WINAPI GetFullPathName(
;  _In_   LPCTSTR lpFileName,
;  _In_   DWORD nBufferLength,
;  _Out_  LPTSTR lpBuffer,
;  _Out_  LPTSTR *lpFilePart
;  );
  

Procedure.s GetFullPathName( cPath.s )
	Protected cFullPath.s, *Buffer, nSize=#MAX_PATH, *FilePart
	*Buffer = AllocateMemory(nSize)
	If *Buffer
		nSize = GetFullPathName_(@cPath,nSize,*Buffer,@*FilePart)
		If nSize 
			cFullPath = PeekS(*Buffer,nSize)
			If *FilePart
				Debug PeekS(*FilePart)
			EndIf 
			Debug cFullPath
		EndIf
		FreeMemory(*Buffer)
	Else
		Debug "Alloc failure"
	EndIf
	ProcedureReturn cFullPath
EndProcedure

Debug GetFullPathName(GetFilePart(ProgramFilename()))

Re: GetFullPathName_() - PB bug?

Posted: Sun Oct 28, 2018 8:13 pm
by mk-soft
Our buffer to small. Its Unicode...

PB is calling GetFullPathNameW(...)

Update path limits

Code: Select all

;DWORD WINAPI GetFullPathName(
;  _In_   LPCTSTR lpFileName,
;  _In_   DWORD nBufferLength,
;  _Out_  LPTSTR lpBuffer,
;  _Out_  LPTSTR *lpFilePart
;  );

CompilerIf #PB_Compiler_Unicode
  #PATH_MAX = 32767
CompilerElse
  #PATH_MAX = #MAX_PATH
CompilerEndIf
   
Procedure.s GetFullPathName( cPath.s )
  Protected cFullPath.s, *Buffer, nSize, *FilePart
  *Buffer = AllocateMemory(#PATH_MAX * SizeOf(Character))
  If *Buffer
    nSize = GetFullPathName_(@cPath,#PATH_MAX,*Buffer,@*FilePart)
    If nSize 
      cFullPath = PeekS(*Buffer,nSize)
      If *FilePart
        Debug PeekS(*FilePart)
      EndIf 
    EndIf
    FreeMemory(*Buffer)
  Else
    Debug "Alloc failure"
  EndIf
  ProcedureReturn cFullPath
EndProcedure

r1.s = GetFullPathName(GetFilePart(ProgramFilename()))
Debug r1
ASM-Output
; nSize = GetFullPathName_(@cPath,#MAX_PATH,*Buffer,@*FilePart)
LEA rax,[rsp+72]
MOV rax,rax
PUSH rax
PUSH qword [rsp+64]
PUSH qword 260
MOV rax,qword [rsp+64]
MOV rax,rax
PUSH rax
POP rcx
POP rdx
POP r8
POP r9
CALL GetFullPathNameW
MOV qword [rsp+64],rax

Re: GetFullPathName_() - PB bug?

Posted: Sun Oct 28, 2018 9:49 pm
by jassing
mk-soft wrote:Our buffer to small. Its Unicode...
#PATH_MAX = 32767
*Buffer = AllocateMemory(#PATH_MAX * SizeOf(Character))
D'oh! That always stings me. I updated my size to 32767 but forgot to multiply by sizeof(character)...

thank you.

btw: I read that it's not recommended for threaded applications, but there's no workaround suggested, but so far, I haven't seen an issue, using older pb.