Embedding the PC Name in an app Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Widgets
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 534
Joined: Thu Jun 01, 2006 4:36 pm
Location: Right here!

Embedding the PC Name in an app

Post by Widgets »

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
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Embedding the PC Name in an app

Post by ONEEYEMAN »

Hi,
Can you explain why do you want that function to be static?

Thank you
Widgets
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 534
Joined: Thu Jun 01, 2006 4:36 pm
Location: Right here!

Re: Embedding the PC Name in an app

Post by Widgets »

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
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
User avatar
doublemax@work
Super wx Problem Solver
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

Post by doublemax@work »

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?
User avatar
doublemax@work
Super wx Problem Solver
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

Post by doublemax@work »

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
Widgets
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 534
Joined: Thu Jun 01, 2006 4:36 pm
Location: Right here!

Re: Embedding the PC Name in an app

Post by Widgets »

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:

Code: Select all

echo #define PC_NAME  $(COMPUTER_NAME) > $(ProjectDir)\pcNameh.h
will produce the header

Code: Select all

#define PC_NAME  TestPC
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.
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
Post Reply