Solved

CString variables to be used by all dailog boxes

Posted on 2002-04-07
8
193 Views
Last Modified: 2010-08-05
I have CString variables that I created in VC6++ for a dialog box.  and I need to use the information for that variable in another dialog box.  In C using a char string of 80 I can use the extern char to use the info anywhere in other programs.  Now I want to do the same with the CString variable but extern will not work with CString variables.  So how can I make the CString varible gobal to the whole program???
0
Comment
Question by:lcrogers
8 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 50 total points
ID: 6924523
>>but extern will not work with CString variables.
Extern does work with CString variables.

Continue...
0
 
LVL 30

Expert Comment

by:Axter
ID: 6924526
You need to make sure that your extern is in a header (*.h) file, and that you're header file is included in the other *.cpp/*.c file in which you want to access the CString object.
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 6925553
Declare the CString variable in stdafx.h
0
 
LVL 30

Expert Comment

by:Axter
ID: 6925572
>>Declare the CString variable in stdafx.h
That would not be wize.

You would end up with multiple instances of the same named CString object.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 30

Expert Comment

by:Axter
ID: 6925576
You can delcare it extern in your stdafx.h, but a beter method would be to declare it extern in your main header.
Put it extern in your MyAppName.h file.
0
 
LVL 2

Expert Comment

by:christophm
ID: 6926590
1. put a (public) copy of the CString vriables in the App object.
2. Modify the DDX (if you are using DDX) by having that function copy the Dialog bound CString variables to the copies in the app object.
3. Now from anywhere (any dialog) in the app you can get the copies ::AfxGetApp()->a_CString_Copy;

Or be fancier and make the CString's in the app object the 'real' thing and not just a copy(ies).

cm
0
 
LVL 11

Expert Comment

by:griessh
ID: 6957245
Dear lcrogers

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "Axter"

comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 6979194
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now