Working on a LAN & using Git, some of my utilities might get compiled on any one PC, which is OK until I need to find out which PC holds the latest version of a specific utility.
What I would like to do is it include the PC name of the PC where the utility is being compiled into the About dialog as a string for easy reference.
My first thoughts were to either use an environment variable or wxGetHostName(), but neither are 'static' and tied to a specific PC in the way I would like. When using the env variable, each PC would , of course have its one name and in the same way wxGetHostName() will retrieve the current PC the app is running on.
Similarly, embedding a #define PC_NAME in the code will carry along the wrong name, if the code is checked out on a different PC.
Naturally, I am signed in to each PC with the same user name.
Is the solution so simple that I don't see it or does any one have a way to get what I am looking for?
TIA
Embedding the PC Name in an app Topic is solved
Embedding the PC Name in an app
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
MSVC Express 2019/2022
wxWidgets 3.2.2
Re: Embedding the PC Name in an app
Hi,
Can you explain why do you want that function to be static?
Thank you
Can you explain why do you want that function to be static?
Thank you
Re: Embedding the PC Name in an app
My bad explanation.
No need to have the function static.
It simply MUST be something outside the code at run time so that it reflects the name or ID of the PC on which that specific version of the app is compiled and linked
No need to have the function static.
It simply MUST be something outside the code at run time so that it reflects the name or ID of the PC on which that specific version of the app is compiled and linked
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
MSVC Express 2019/2022
wxWidgets 3.2.2
- doublemax@work
- Super wx Problem Solver
- Posts: 474
- Joined: Wed Jul 29, 2020 6:06 pm
- Location: NRW, Germany
Re: Embedding the PC Name in an app
I coudln't find a macro like __TIME__ that contains the PC Name or anything similar. How about a small Header File, that's Not Part of the repo that contains an identifier as #define?
- doublemax@work
- Super wx Problem Solver
- Posts: 474
- Joined: Wed Jul 29, 2020 6:06 pm
- Location: NRW, Germany
Re: Embedding the PC Name in an app
In visual Studio you can also define pre- and Post- build Events where you can Run executables. You could enter a small Powershell Script that creates above mentioned Header File automatically
Re: Embedding the PC Name in an app
Thank you,
yes the data has to be set up during the compile/link phase, not during run-time.
Fortunately I am using the MSVC IDE and your suggestion to use a pre-build step is the perfect and relatively easy solution.
In fact it is greatly simplified, because during the build phases, all of the IDE's macros are available and they include any environment variables.
Assuming I have an environment variable defined: COMPUTER_NAME = TestPC
My quick test showed perfect results for a simple pre-build command:
will produce the header
This command can then be used even in a sub-project, such as that for the About dialog.
And the header can be included wherever it is neded.
In this way the code also stays with the app project and needs no special attention to make sure it is backed up.
yes the data has to be set up during the compile/link phase, not during run-time.
Fortunately I am using the MSVC IDE and your suggestion to use a pre-build step is the perfect and relatively easy solution.
In fact it is greatly simplified, because during the build phases, all of the IDE's macros are available and they include any environment variables.
Assuming I have an environment variable defined: COMPUTER_NAME = TestPC
My quick test showed perfect results for a simple pre-build command:
Code: Select all
echo #define PC_NAME $(COMPUTER_NAME) > $(ProjectDir)\pcNameh.h
Code: Select all
#define PC_NAME TestPC
And the header can be included wherever it is neded.
In this way the code also stays with the app project and needs no special attention to make sure it is backed up.
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
MSVC Express 2019/2022
wxWidgets 3.2.2