Link to home
Start Free TrialLog in
Avatar of mskohut
mskohut

asked on

Addit. info in linking MFC apps

How is it possible to include the Win NT user name or the name of my PC into my MFC executable during linking of my application???

I want to include a message box in my application where the person or the PC name who linked the app can be displayed.

Thanks,
Markus
Avatar of Zoppo
Zoppo
Flag of Germany image

Hi mskohut,

I imagine a way to do this is to create an Visual Studio Add-In, which handles the Application.BeforeBuildStart event. In the Add-In you can get the user's name using GetUserName() and perhaps write this into an resource include file as a string table entry which can be used for your message box.

Unfortunately I do not have experience creating VS-AddIns, but I can't imagine another way.

hope that helps,

ZOPPO
Add a custom build step to your project which echoes this information to a .rc file, e.g.

info.cmd:

// set beginning of the .rc
echo "STRINGTABLE DISCARDABLE " >> info.rc
echo "BEGIN" >> info.rc
echo %USERNAME% >> info.rc            
echo %COMPUTERNAME% >> info.rc            
END


// set end of the .rc
Uhh, what a shame .... tried to shoot a sparrow with a cannon ball .... please disregard my previous comment .... I gonna hide in a hole and read some book about VC ... :-\

zoppo
>>Uhh, what a shame

Not at all ;-)

Usually I'd do the above using a makefile - usually I use cunstom build steps to create RPC stubs or sth. like that, but they'd work for this also...
Avatar of mskohut
mskohut

ASKER

> Add a custom build step ...

Yes, it works.

I use following custom build steps for one of my header files:

echo STRINGTABLE DISCARDABLE >> info.rc
echo BEGIN >> info.rc
echo IDS_BUILD_USERNAME "%USERNAME%" >> info.rc
echo IDS_BUILD_COMPUTERNAME "%COMPUTERNAME%" >> info.rc
echo END >> info.rc

I have still a small problem:
I want to delete the info.rc file after the build (because I want to genetate a new file at EVERY build), so I added following post-build step to my project:

del info.rc

The first build works, but at the end I get the message:

Error scanning file C:\.....\info.rc for dependencies.

Subsequent builds won't generate the info.rc file any more.

How can I make it better?
Replace

echo STRINGTABLE DISCARDABLE >> info.rc // append to file

with

echo STRINGTABLE DISCARDABLE > info.rc // create new file

ZOPPO
Avatar of mskohut

ASKER

OK, but it doesn't solve following problem:

I build my application => info.rc will be created.

I login as a new user and build my application => a new info.rc should be created.

So it would be good if I can delete my info.rc after every build. This should be automatically done regardless on which computer I or another person builds the application. So the delete command has to be included somewhere in the project file.
Avatar of mskohut

ASKER

OK, but it doesn't solve following problem:

I build my application => info.rc will be created.

I login as a new user and build my application => a new info.rc should be created.

So it would be good if I can delete my info.rc after every build. This should be automatically done regardless on which computer I or another person builds the application. So the delete command has to be included somewhere in the project file.
I do not see the problem exactly, because the info.rc file is overwritten every build, but you can set a Post Build command like

del info.rc

ZOPPO
Avatar of mskohut

ASKER

> I do not see the problem exactly, because the info.rc file is overwritten every build, ...

No. If I change nothing in my project and login as a new user and then press F7 in my project, NOTHING will be re-build.

> ... but you can set a Post Build command like del info.rc

I tried this, but I get an error message: see comment 5 in Question History.

> No. If I change nothing in my project and login as a new user and then press F7 in my project, NOTHING will be re-build.

Of course nothing will be rebuilt because nothing has changed.

The error message may occur because the info.rc file does not belong to the project.

Perhaps it's better if you're making a command file which creates a new info.rc file and put this into the autostart folder to make sure that with every new login a new info.rc file is created. So you also make sure that it'll be rebuilt after new login.

ZOPPO
Avatar of mskohut

ASKER

I found a solution:

In the "Custom Build" tab, I dont't write "info.rc" into the "Outputs" field, but "dummy".

The file "dummy" never exists, so the Custom Build will be done at EVERY build.
Avatar of mskohut

ASKER

TO JKR:

Could you please re-send your comment as a question, so that I can give you your points?

Thanks,
Markus
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial