![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 8
Rep Power: 0
![]() |
Read Programm Version from outside
Hi, this is my problem:
I have two programms (both made by me): my main application and an external one. The external one must read the main app version. The version is declared as: #define APP_VERSION (XX). I dont know very much about compilers/linkers, but I think that the defines are not mapped into the exe. However, I use APP_VERSION to print in some places of my app, so somewhere in exe it should appear. But, as the main app changes some code in new versions, I can't read in a some fixed exe position, and be sure to always read version ok. My question is, how can I make some code, or tell the compiler/linker to map a constant in the exe in an fixed position? Until now, I am doing this: main()
{
/* I only use this printf() to print version, not because I want to show it */
/* here, but to make it appear in the exe in a fixed pos, as it is the first */
/* instruction executed, so it is easy to find it in exe */
printf("%d", APP_VERSION);
...
...
} |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Why don't you just declare a local variable there and initialize it to the version number? Essentially, that's what you're doing with the parameter to "printf".
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
If the main app is always running, you can use an environment variable...
The following example changes the value of the HOME environment variable to the value /usr/home. #include <stdlib.h> ... static char *var = "HOME=/usr/home"; int ret; ret = putenv(var);
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
I think he means something like fingerprinting or image file version identifiers.
Let's try the easiest one put a what string at the beginning of a string. Put this near the top of your code static char *MYidentifier="@(#) programname version 1.1.0"; ident and what will display it for you. You can write your own ident module - call strstr() to find the start of the identifier. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Feb 2005
Posts: 8
Rep Power: 0
![]() |
Thanks for the replies.
DaWei, before doing the printf() I had tought about your suggestion. However, I wasn't sure about compiler's optimization, so if I declare a variable but I dont use, the compiler may eliminate it, even when I initialized it. Certainly I could do this: main()
{
unsigned int nVer = APP_VERSION;
nVer = nVer; // Compiler, optimize all but no this!
}I can also add some ASM code, I will test it. By the way, please correct me if I am wrong, I think there is a way to tell the linker to add a fixed block in a fixed position in the exe. Regards, |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|