Re: Help! GPF
- Posted by "Cuny, David" <David.Cuny at DSS.CA.GOV> Aug 05, 1999
- 494 views
Bernie wrote: > Your definition of AppendMenuA is not correct > in win32 library. It should be > AppendMenuA { C_LONG, C_UINT, C_UINT, C_POINTER } C_INT My documentation shows: BOOL AppendMenu( HMENU hMenu, UINT uFlags, UINT uIDNewItem, LPCTSTR lpNewItem ); and I've always assumed that any handle reference gets coded as a C_POINTER instead of C_LONG. Perhaps Rob could clear this up? This doesn't appear to be a C_POINTER/C_LONG problem, because I'm passing the handle to various Windows functions, and they seem to be working properly - attaching the menu item to the menu, and so on. And, of course, I tested it and it was still broken. But I *think* I know what the problem is, although the logic still escapes me. For reasons that still escape me, menu items and controls are ending up sharing the *same* window handle. So when find() attempts to look the handle up, it stops at the menu item, instead of finding the control. There are two possibilities: I'm reading the handle wrong, or there really are duplicate handles. Since code that uses these handles appears to work, my suspicion is that the handles are not unique, and Windows relies on context to make sense of them. If this is incorrect, someone please clue me in on what's really going on. Here's a dump of the window handles in an errant Win32Lib program: window_handle = {2652,2340,2340,2344,2344,2344,2348, 2348,2348,2348,2348,2348,2348,2348,2348,2348,2348, 2348,2348,2348,2352,2352,2352,2352,2352,2352,2356, 2356,2656,2660,2664,2668,2672,2676,2680,2684,2688, 2692,2696,2700,2708,2720,2716,2712,2724,2736,2108, 2744,2728,2752,2748,2704,2732,2760,2740,1816,1888, 1812,1876,1880,1828,1824,1820,1840,1836,1832,1884, 1892,1896,1872,1704,1708,1848,1852,1856,1860,1864, 1868,1844,1900,1808,1744,1736,1740,2764,2768,2400, 2784,2776,2800,2252,2780,2772,2808,2796,2348,2840, 2356,2340,2360,2424,2848,2344,2856,2852,2336,2836, 2864,2868,2872,2876,2880,2884,2888,2892,2896,2900, 2904,2908,2912,2916,2920,2924,2928,2932,2936,2940, 2944,2948,2952,2956,2960,2964,2968,2972,2976,2980, 2984,2988,2992,2996,3000,3004,3008,3012,3016,3020, 3024} There have always been duplicate handles in the window_handle list - for example, the window handle of a MenuItem actually contains the handle of the parent Menu. This doesn't cause problems with find(), since it stops at the first control that it finds, and the window has to be defined before the menu. Controls #2 and #3 show the sharing of a handle between a Menu and a MenuItem. The error is that control #83 is misidentified as #27 - they both share the same value of 2356 as their handle. There are several solutions I can think of: 1. Exclude menus and menu items from the search 2. Create another sequence of window and control handles 3. Store the value in the GWL_USERDATA area I'll probably go with option #3, since that's what Llama uses. -- David Cuny