Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7c9f36c

Browse files
committedAug 30, 2021
win32: fix type of SetWindowLongPtr
1 parent 628bf1d commit 7c9f36c

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed
 

‎Graphics/Win32/LayeredWindow.hsc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module Graphics.Win32.LayeredWindow (module Graphics.Win32.LayeredWindow, Graphi
1414
import Control.Monad ( void )
1515
import Data.Bits ( (.|.) )
1616
import Foreign.Ptr ( Ptr )
17-
import Foreign.Marshal.Utils ( with )
1817
import Graphics.Win32.GDI.AlphaBlend ( BLENDFUNCTION )
1918
import Graphics.Win32.GDI.Types ( COLORREF, HDC, SIZE, SIZE, POINT )
2019
import Graphics.Win32.Window ( WindowStyleEx, c_GetWindowLongPtr, c_SetWindowLongPtr )
@@ -27,7 +26,7 @@ import System.Win32.Types ( DWORD, HANDLE, BYTE, BOOL, INT )
2726
toLayeredWindow :: HANDLE -> IO ()
2827
toLayeredWindow w = do
2928
flg <- c_GetWindowLongPtr w gWL_EXSTYLE
30-
void $ with (fromIntegral $ flg .|. (fromIntegral wS_EX_LAYERED)) $ c_SetWindowLongPtr w gWL_EXSTYLE
29+
void $ c_SetWindowLongPtr w gWL_EXSTYLE (flg .|. (fromIntegral wS_EX_LAYERED))
3130

3231
-- test w = c_SetLayeredWindowAttributes w 0 128 lWA_ALPHA
3332

‎Graphics/Win32/Window.hsc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import Foreign.ForeignPtr (withForeignPtr)
2323
import Foreign.Marshal.Utils (maybeWith)
2424
import Foreign.Marshal.Alloc (allocaBytes)
2525
import Foreign.Marshal.Array (allocaArray)
26-
import Foreign.Ptr (FunPtr, Ptr, castFunPtrToPtr, castPtr, nullPtr)
27-
import Foreign.Ptr (intPtrToPtr, castPtrToFunPtr, freeHaskellFunPtr)
26+
import Foreign.Ptr (FunPtr, Ptr, castFunPtrToPtr, nullPtr)
27+
import Foreign.Ptr (intPtrToPtr, castPtrToFunPtr, freeHaskellFunPtr,ptrToIntPtr)
2828
import Foreign.Storable (pokeByteOff)
2929
import Foreign.C.Types (CIntPtr(..))
3030
import Graphics.Win32.GDI.Types (HBITMAP, HCURSOR, HDC, HDWP, HRGN, HWND, PRGN)
@@ -204,6 +204,9 @@ type WindowClosure = HWND -> WindowMessage -> WPARAM -> LPARAM -> IO LRESULT
204204
foreign import WINDOWS_CCONV "wrapper"
205205
mkWindowClosure :: WindowClosure -> IO (FunPtr WindowClosure)
206206

207+
mkCIntPtr :: FunPtr a -> CIntPtr
208+
mkCIntPtr = fromIntegral . ptrToIntPtr . castFunPtrToPtr
209+
207210
-- | The standard C wndproc for every window class registered by
208211
-- 'registerClass' is a C function pointer provided with this library. It in
209212
-- turn delegates to a Haskell function pointer stored in 'gWLP_USERDATA'.
@@ -218,10 +221,10 @@ setWindowClosure :: HWND -> WindowClosure -> IO (Maybe (FunPtr WindowClosure))
218221
setWindowClosure wnd closure = do
219222
fp <- mkWindowClosure closure
220223
fpOld <- c_SetWindowLongPtr wnd (#{const GWLP_USERDATA})
221-
(castPtr (castFunPtrToPtr fp))
222-
if fpOld == nullPtr
224+
(mkCIntPtr fp)
225+
if fpOld == 0
223226
then return Nothing
224-
else return $ Just $ castPtrToFunPtr fpOld
227+
else return $ Just $ castPtrToFunPtr $ intPtrToPtr $ fromIntegral fpOld
225228

226229
{- Note [SetWindowLongPtrW]
227230
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -240,7 +243,7 @@ foreign import WINDOWS_CCONV unsafe "windows.h SetWindowLongPtrW"
240243
#else
241244
# error Unknown mingw32 arch
242245
#endif
243-
c_SetWindowLongPtr :: HWND -> INT -> Ptr LONG -> IO (Ptr LONG)
246+
c_SetWindowLongPtr :: HWND -> INT -> LONG_PTR -> IO (LONG_PTR)
244247

245248
#if defined(i386_HOST_ARCH)
246249
foreign import WINDOWS_CCONV unsafe "windows.h GetWindowLongW"

‎Win32.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Win32
2-
version: 2.12.0.1
2+
version: 2.13.0.0
33
license: BSD3
44
license-file: LICENSE
55
author: Alastair Reid, shelarcy, Tamar Christina

‎changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog for [`Win32` package](http://hackage.haskell.org/package/Win32)
22

3+
## 2.13.0.0 August 2021
4+
5+
* Fix type of c_SetWindowLongPtr. See #180
6+
37
## 2.12.0.1 June 2021
48

59
* A small fix for WinIO usage. See #177

0 commit comments

Comments
 (0)
Please sign in to comment.