Link to home
Start Free TrialLog in
Avatar of bod_1
bod_1

asked on

retain values in structure between functions

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.
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

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
Avatar of nietod
nietod

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.
Avatar of bod_1

ASKER

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.