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
Solved

retain values in structure between functions

Posted on 1998-02-11
3
208 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

766 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