Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

retain values in structure between functions

Posted on 1998-02-11
3
Medium Priority
?
213 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 80 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

972 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