Page 1 of 1
Posted: Sun Oct 14, 2001 10:20 pm
by BackupUser
Restored from previous forum. Originally posted by Cantor.
Hi there!
Is there a way to receive the path of a Windows-PB-application after starting it? In AMIGA-OS it is the path of "PROGDIR:". What about Windows?
--
Best regards,
Martin
Posted: Mon Oct 15, 2001 12:24 am
by BackupUser
Restored from previous forum. Originally posted by wayne1.
AllocateMemoryBank(0,300,0)
AllocateMemoryBank(1,300,0)
a=GetFullPathName_("test.exe",300, useMemoryBank(0),useMemoryBank(1));
MessageRequester("Path to this executable",peeks(UseMemoryBank(0)),0)
###########################################################################
DWORD GetFullPathName(
LPCTSTR lpFileName, // file name
DWORD nBufferLength, // size of path buffer
LPTSTR lpBuffer, // path buffer
LPTSTR *lpFilePart // address of file name in path
);
Parameters
lpFileName
[in] Pointer to a null-terminated string that specifies a valid file name. This string can use either short (the 8.3 form) or long file names.
nBufferLength
[in] Specifies the size, in TCHARs, of the buffer for the drive and path.
lpBuffer
[out] Pointer to a buffer that receives the null-terminated string for the name of the drive and path.
lpFilePart
[out] Pointer to a buffer that receives the address (in lpBuffer) of the final file name component in the path.
Return Values
If the GetFullPathName function succeeds, the return value is the length, in TCHARs, of the string copied to lpBuffer, not including the terminating null character.
If the lpBuffer buffer is too small, the return value is the size of the buffer, in TCHARs, required to hold the path.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
GetFullPathName merges the name of the current drive and directory with the specified file name to determine the full path and file name of the specified file. It also calculates the address of the file name portion of the full path and file name. This function does not verify that the resulting path and file name are valid or that they refer to an existing file on the associated volume.
GetFullPathName does no conversion of the specified file name, lpFileName. If the specified file name exists, you can use GetLongPathName and GetShortPathName to convert to long and short path names, respectively.
MAPI: For more information, see Syntax and Limitations for Win32 Functions Useful in MAPI Development.
Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.
Edited by - wayne1 on 15 October 2001 01:33:33
Posted: Mon Oct 15, 2001 8:24 am
by BackupUser
Restored from previous forum. Originally posted by Cantor.
Hi Wayne1!
Thank You for answering quickly. Your source code is very useful for my application.
Is there a way to get only the path of the folder of an application?
--
Best regards,
Martin
Posted: Mon Oct 15, 2001 8:17 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
Is there a way to get only the path of the folder of an application?
Does the GetPathPart command do it? (I haven't tried it).
Posted: Sun Oct 21, 2001 3:01 am
by BackupUser
Restored from previous forum. Originally posted by wayne1.
;Cantor GetPathPart() will work fine but I submitted this code just FYI
AllocateMemoryBank(0,300,0)
AllocateMemoryBank(1,300,0)
a=GetFullPathName_("test.exe",300, useMemoryBank(0),useMemoryBank(1));
a$=peeks(UseMemoryBank(0))
while char=0
count=count+1
c$=Right(a$,count)
char=FindString(c$, "\", 0)
Wend
a$=left(a$,(len(a$)-(count-1)))
MessageRequester("Path Part of Full Path",a$,0)
Posted: Mon Dec 10, 2001 4:16 am
by BackupUser
Restored from previous forum. Originally posted by PB.
a=GetFullPathName_("test.exe",300, useMemoryBank(0),useMemoryBank(1));
And what if the user renames your exe?
I prefer to use this code to avoid that possibility (and memory banks):
Code: Select all
appdir$=space(255) : GetCurrentDirectory_(255,appdir$)
if right(appdir$,1)"\" : appdir$=appdir$+"\" : endif
PB - Registered PureBasic Coder
Edited by - PB on 10 December 2001 04:19:35
Posted: Wed Dec 12, 2001 5:08 am
by BackupUser
Restored from previous forum. Originally posted by wayne1.
Renaming the .exe wouldnt make any difference as that is just an
unverified name it could be anything (rename it and try) and still return the current directory although incorrect app name so your method would be the best for the first example
Edited by - wayne1 on 12 December 2001 05:26:42
Posted: Wed Dec 12, 2001 6:33 am
by BackupUser
Restored from previous forum. Originally posted by PB.
Renaming the .exe wouldnt make any difference as that is just an
unverified name it could be anything (rename it and try) and still return the current directory although incorrect app name so your method would be the best for the first example
I stand corrected.
PB - Registered PureBasic Coder