Dennis Schridde schreef:
> Am Sonntag, 26. November 2006 23:33 schrieb Giel van Schijndel:
>
>> Dennis Schridde schreef:
>>
>>> Am Sonntag, 26. November 2006 18:43 schrieb Giel van Schijndel:
>>>
>>>> Dennis Schridde schreef:
>>>>
>>>>>> The changes to trunk/lib/widget/scrap.c cause a compiler error
>>>>>> (comparison of int with pointer). This error will only be raised while
>>>>>> compiling a Windows build. I don't have the patches but according to
>>>>>> the description above I'm guessing number 003.
>>>>>>
>>>>>> Also the previous style of comparing those two values would result in
>>>>>> comparing pointer-addresses rather than a value comparison.
>>>>>> (See the typedef of HWND in windef.h).
>>>>>>
>>>>> Seems like this more complicated...
>>>>>
>>>>> scrap.c sets SDL_Window (I don't think the name is choosen very wise,
>>>>> btw) to info.window, which is of type HWND...
>>>>> Can we revert SDL_Window back to HWND and then compare whatever type
>>>>> that is with GetClipboardOwner? Would that be the clean way of doing
>>>>> this? Or does MS recommend to use that HWND.i thing instead?
>>>>>
>>>> The currently unmodified comparison which causes the compiler to abort
>>>> is this one:
>>>> ( GetClipboardOwner() != SDL_Window )
>>>>
>>>> Assuming GetClipboardOwner returns HWND this is the comparison being
>>>> made: ( (HWND) != (int) )
>>>> which equals:
>>>> ( (struct HWND__{int i;}*HWND) != (int) )
>>>>
>>>> If SDL_Window is declared as HWND however you get this:
>>>> ( (struct HWND__{int i;}*HWND) != (struct HWND__{int i;}*HWND) )
>>>>
>>>> So the current comparison as it is being made is wrong in all cases,
>>>> because all that the current comparison does is comparing pointer
>>>> addresses. This will when SDL_Window is declared as HWND always return
>>>> true (!=),
>>>>
>>> Why will it return true?
>>> I thought HWND is a pointer to some blob, handled and allocated by
>>> Windows, associated with the window? So this blob is allways at the same
>>> position for the same window, so you can compare the pointer to it, can't
>>> you? And actually SDL_Window is set from a SDL_WMinfo.window thingy,
>>> which actually is a HWND, very probably handed over by Windows to SDL,
>>> being a reference for the window. So I don't see why we can't compare it
>>> to some other HWND we get from Windows. (Or why that should allways be
>>> true...)
>>>
>> Well the problem is that the hWnd isn't a true pointer to a memory
>> address (see: http://en.wikipedia.org/wiki/Smart_pointer#Handles), but
>> more of an index number windows uses to manage memory chunks. Like an
>> index number to an array that contains the real pointers, whereas only
>> the windows API has access to that "array" to use the values within it.
>> So, if you compare the a pointer to a variable containing the hWnd value
>> with the hWnd value itself you probably will never get a match. Even
>> more so if you compare a pointer to variable A containing hWnd A with a
>> pointer to variable B containing hWnd A.
>>
> Did I get this right?
>
> In "HWND foo", foo is a pointer to a MS_HWND, which contains an integer,
> which
> is an index into an array of pointers to windows?
> Ugh!
>
> So if we compare 2 pointers to MS_HWND, they might (will?) be different, even
> if in the end they mean the same window?
> Scary...
>
Yes you've got it right.
> So what we need to compare is this index into the array of pointers to
> windows? And that is foo->i?
>
> Sounds ugly, but well, if that's what MS decided, we need to use what we've
> been given..
Whatever reason they have for it, that's indeed how it is.So attached I've got a patch that makes sure ->i is appended to all variables of type HWND (in scrap.c, two lines only). What's most important about this patch is that it enables you to compile wz on Windows (using MinGW). -- Giel
Index: lib/widget/scrap.c
===================================================================
--- lib/widget/scrap.c (revision 512)
+++ lib/widget/scrap.c (working copy)
@@ -298,7 +298,7 @@
#elif defined(WIN_SCRAP)
/* * */
- SDL_Window = info.window;
+ SDL_Window = info.window->i;
retval = 0;
#elif defined(QNX_SCRAP)
@@ -324,7 +324,7 @@
#elif defined(WIN_SCRAP)
/* * */
- retval = ( GetClipboardOwner() != SDL_Window );
+ retval = ( GetClipboardOwner()->i != SDL_Window );
#elif defined(QNX_SCRAP)
/* * */
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Warzone-dev mailing list [email protected] https://mail.gna.org/listinfo/warzone-dev
