Link to home
Start Free TrialLog in
Avatar of lcrogers
lcrogers

asked on

CString variables to be used by all dailog boxes

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???
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America 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
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.
Avatar of pagladasu
pagladasu

Declare the CString variable in stdafx.h
>>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.
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.
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
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: https://www.experts-exchange.com/commspt/

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
Force accepted

** Mindphaser - Community Support Moderator **