Solved

retain values in structure between functions

Posted on 1998-02-11
3
211 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
[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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

623 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