Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Addit. info in linking MFC apps

Posted on 1999-07-29
14
Medium Priority
?
763 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:mskohut
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
14 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 1311934
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 1311935
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
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 1311936
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
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 86

Expert Comment

by:jkr
ID: 1311937
>>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...
0
 

Author Comment

by:mskohut
ID: 1311938
> 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?
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 1311939
Replace

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

with

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

ZOPPO
0
 

Author Comment

by:mskohut
ID: 1311940
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.
0
 

Author Comment

by:mskohut
ID: 1311941
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.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 1311942
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
0
 

Author Comment

by:mskohut
ID: 1311943
> 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.

0
 
LVL 31

Expert Comment

by:Zoppo
ID: 1311944
> 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
0
 

Author Comment

by:mskohut
ID: 1311945
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.
0
 

Author Comment

by:mskohut
ID: 1311946
TO JKR:

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

Thanks,
Markus
0
 
LVL 86

Accepted Solution

by:
jkr earned 800 total points
ID: 1311947
Thanx ;-)

Hmm, das hätte wohl auch ein rein deutschsprachiger Thread ('tschuldigung, 'Diskussionsfaden' natürlich <lol> werden können ;-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question