GetFullPathName_() - PB bug?

Windows specific forum
jassing
Addict
Addict
Posts: 1774
Joined: Wed Feb 17, 2010 12:00 am

GetFullPathName_() - PB bug?

Post 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()))
User avatar
mk-soft
Always Here
Always Here
Posts: 5402
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: GetFullPathName_() - PB bug?

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
jassing
Addict
Addict
Posts: 1774
Joined: Wed Feb 17, 2010 12:00 am

Re: GetFullPathName_() - PB bug?

Post 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.
Post Reply