How can a PB console app find (from the OS) the name, at run time, of its exe file and the folder in which it resides, bearing in mind that the exe could have been renamed after compilation and that the current directory (i.e. the one you are "in" when you run the program) is not necessarily where the exe lives.
The concept of the current directory (a DOS term) is quite relevant under Windows. It is the "Start in" or "Working" folder specified in the properties of the shortcut used to run the exe file. (It does NOT have to be the folder in which the application file resides, and sometimes SHOULD NOT be.)
Some years ago, I wrote a calendar program in PB 3.1 for DOS (all I had back then), which included the following advice to users in the installation instructions:
On a computer that is shared by several people, even if they all share a single user account, each person can customise Calendar with their own preferred colour scheme and their own personal set of diary entries without affecting any other person's use of Calendar. Just copy the files Colors.txt and UserData.txt to a personal folder of your own choice, then make your own shortcut for Calendar, and in the shortcut's properties, specify that folder as the "working" or "start in" folder. You can then edit your own private copies of Colors and UserData to personalise Calendar according to your own preferences.
However, the program also uses other ancillary files that are not specific to individual users. Logically, there should only be a single set of those files and they should reside in the application's folder, and the app should read them from that folder even if a different "start in" folder is specified in the properties of the app's shortcut.
With PB for DOS, I was able to identify the program's native directory and its exe name at run time by: (a) calling DOS interrupt 21/62 to find the program's PSP address, (b) finding, in the PSP, a pointer to the program's environment block, and (c) finding, just beyond the end of the env't table, after a pair of bytes ASCII 1,0, the pathname by which the program was invoked, which is stored at that memory location by DOS when it loads the program into memory.
(BTW, in case anyone is interested in the specifics of this, I am attaching the source code for it, which is extensively documented.)
I now want to port the program to Wndows as a console app. Is there a technique that can be used in PBCC (I am using version 3.04) to get the same information from Windows?
The concept of the current directory (a DOS term) is quite relevant under Windows. It is the "Start in" or "Working" folder specified in the properties of the shortcut used to run the exe file. (It does NOT have to be the folder in which the application file resides, and sometimes SHOULD NOT be.)
Some years ago, I wrote a calendar program in PB 3.1 for DOS (all I had back then), which included the following advice to users in the installation instructions:
On a computer that is shared by several people, even if they all share a single user account, each person can customise Calendar with their own preferred colour scheme and their own personal set of diary entries without affecting any other person's use of Calendar. Just copy the files Colors.txt and UserData.txt to a personal folder of your own choice, then make your own shortcut for Calendar, and in the shortcut's properties, specify that folder as the "working" or "start in" folder. You can then edit your own private copies of Colors and UserData to personalise Calendar according to your own preferences.
However, the program also uses other ancillary files that are not specific to individual users. Logically, there should only be a single set of those files and they should reside in the application's folder, and the app should read them from that folder even if a different "start in" folder is specified in the properties of the app's shortcut.
With PB for DOS, I was able to identify the program's native directory and its exe name at run time by: (a) calling DOS interrupt 21/62 to find the program's PSP address, (b) finding, in the PSP, a pointer to the program's environment block, and (c) finding, just beyond the end of the env't table, after a pair of bytes ASCII 1,0, the pathname by which the program was invoked, which is stored at that memory location by DOS when it loads the program into memory.
(BTW, in case anyone is interested in the specifics of this, I am attaching the source code for it, which is extensively documented.)
I now want to port the program to Wndows as a console app. Is there a technique that can be used in PBCC (I am using version 3.04) to get the same information from Windows?
Comment