struct issue

Hello all, I'm facing a strange issue with a struct array problem,
I have wrote a simple struct that contains a UINT and a callback function pointer like so:

struct MESSAGE_HANDLE
{
UINT message;
callback MessageHandler;
};

now later, few lines of code down, when I process the struct above, it sees only the first UINT message, the rest of the struct all are zeros (0x0000)...
(the struct is static and is an array of 3 entries so far.)

hope I was clear, hope anyone can help me guys,
greets!

Last edited on
You haven't given us enough information. Are you sure the callback isn't just NULL?
the callback is a lambda

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
static MESSAGE_HANDLE msgTable[] = 
{
	{
		WM_DESTROY,[](HWND, WPARAM, LPARAM)->LRESULT
		{
			PostQuitMessage(0);
			return 0;
		}
	},
	{
		WM_LBUTTONDOWN, [](HWND _hwnd, WPARAM , LPARAM)->LRESULT
		{
			SetFocus(_hwnd);
			return 0;
		}
	},
	{
		WM_KEYDOWN, [](HWND _hwnd, WPARAM _wparam, LPARAM)->LRESULT
		{
			if (LOWORD(_wparam) == 0x1b){ SendMessageW(_hwnd, WM_CLOSE, 0, 0); }
			return 0;
		}
	}
};
Last edited on
Have you tried stepping through the code with a debugger and observing the values in your structures as you go through? You should be able to isolate a point where it has a value you don't expect.
the Watch window shows that the array has 3 entries, but all are zero besides the very first UINT in the array, which is WM_DESTROY (0x002).
I just wonder, what makes the first argument present in the array, but the rest not..
the struct aligment in the compiler properties is set to default, i tried #pragma pack()... nothing changes
How are the structures being assigned to? Do you assign a callback then immediately observe it to not actually be stored in the structure?
Figured it out just now...

lambdas require the Common Runtime startup function. I have overwritten it to "clean" my executable a bit.. but to use lambdas I must have it.
so now using the "good" old wWinMain() all works fine
Topic archived. No new replies allowed.