Solved

retain values in structure between functions

Posted on 1998-02-11
3
202 Views
Last Modified: 2010-04-10
I have a structure in my dialog's header file. One function creates an instance of the structure and stores info into its members. I need a second function (button press) to access that data. If i create a second instance of the structure with the same name as the instance in the first it will clear the data stored by the first?
How can i access the the data from the first instance of the structure in a seperate function?
Thanks in advance.
0
Comment
Question by:bod_1
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 20 total points
ID: 1181829
I find your question a little confusing, but let me take a stab.

There are two ways around this type of problem.  

If only one dialog box (for this data) can be open at a time, you can store the information in a global variable, or use a global pointer to access the information.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1181830
If you might have multiple dialogs that edit multiple copues (seperate instances) of this data simultaniously, that won't work.  For that case you must store a pointer to the data to be edited with each dialog box.  

To do this You can use SetWindowLong() and GetWindowLong() with the GWL_USERDATA index to get and set the pointer associated with the dialog box.  You will probably want to pass a pointer to the data when you create the dialog box using one of the dialog creation procedures that end in "param", like CreateDialogParam().  This way you can set the pointer in the dialog by intercepting the WM_CREATE message.

Hope this is what you were looking for.
0
 

Author Comment

by:bod_1
ID: 1181831
Solved!
I was trying to store the info from PROCESSENTRY32 into my own structure. My GetProcessInfo() function I had to declare an instance of my structure.  
My OnButton() was supposed to get the info from the first instance of the structure (from GetProcessInfo()) but the original instance is lost when the function ended.

A global instance of my structure will solve this problem.
Thank you nietod.
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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

760 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

18 Experts available now in Live!

Get 1:1 Help Now