vector arrays go out of scope

Hi,

I've run into a strange problem. I'm trying to process win32 messages and make my app act accordingly. I'm passing the messages in a loop with TranslateMessage() and DispatchMessage, and I intercept them with a LRESULT CALLBACK function. Everything works fine except when the messages are processed the arrays seem to be not in scope, they don't contain anything. When I check for them in the main loop where the messages are dispatched they are present and good, but at message processing they're not. This problem doesn't apply to simple variables, they preserve their values.

here's how I store my variables:
1
2
3
4
5
6
7
8
9
class foo //it is inherited by the class 
          //which contains the message processing function
{
public:
  int a; //this preserves its value
  std::vector<some_type> b; //this doesn't
  
  foo(){}
};


here's the dispatching:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
for(;;) //the class wich contains this inherits the window processing class
{
  MSG msg;
  BOOL return_value = GetMessage(&msg, 0, 0, 0);
  if(return_value == 0)
  {}
  else if(return_value == -1)
  {}
  else
  {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
}


and the message processing:
1
2
3
4
5
6
7
8
9
10
11
12
//this is not static!
LRESULT CALLBACK window::msg_proc(UINT msg, WPARAM wparam, LPARAM lparam)
{
  switch(msg)
  {
    case WM_COMMAND:
    {
      //do something, here the array's size is zero, 
      //so we actually can't do anything
    }
  }
}


is there a way to make my variables stay in scope, or access their content?

Best regards,
Yours3!f

I don't mean to be TFG but you aren't loading anything into your vector at any point with what you've shown us. Can we see that part of your code?

Another Option: Would it be easier to have an instance of your object 'foo' inside of the object that processes the messages instead of inheriting?
ok I finally could solve it, I had to restructure everything based on this tutorial:
http://www.stromcode.com/2008/03/01/cwin32-tutorials/
Last edited on
Topic archived. No new replies allowed.