Skip to content

Commit b1f51c8

Browse files
committed
Add WindwowsString/WindowsFilePath support wrt AFPP
1 parent 9e27ff5 commit b1f51c8

33 files changed

+2554
-975
lines changed

System/Win32/DLL.hsc

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,76 +31,49 @@ module System.Win32.DLL
3131
, lOAD_WITH_ALTERED_SEARCH_PATH
3232
) where
3333

34+
import System.Win32.DLL.Internal
3435
import System.Win32.Types
3536

3637
import Foreign
3738
import Foreign.C
3839
import Data.Maybe (fromMaybe)
3940

40-
##include "windows_cconv.h"
41-
42-
#include <windows.h>
43-
4441
disableThreadLibraryCalls :: HMODULE -> IO ()
4542
disableThreadLibraryCalls hmod =
4643
failIfFalse_ "DisableThreadLibraryCalls" $ c_DisableThreadLibraryCalls hmod
47-
foreign import WINDOWS_CCONV unsafe "windows.h DisableThreadLibraryCalls"
48-
c_DisableThreadLibraryCalls :: HMODULE -> IO Bool
4944

5045
freeLibrary :: HMODULE -> IO ()
5146
freeLibrary hmod =
5247
failIfFalse_ "FreeLibrary" $ c_FreeLibrary hmod
53-
foreign import WINDOWS_CCONV unsafe "windows.h FreeLibrary"
54-
c_FreeLibrary :: HMODULE -> IO Bool
5548

5649
getModuleFileName :: HMODULE -> IO String
5750
getModuleFileName hmod =
5851
allocaArray 512 $ \ c_str -> do
5952
failIfFalse_ "GetModuleFileName" $ c_GetModuleFileName hmod c_str 512
6053
peekTString c_str
61-
foreign import WINDOWS_CCONV unsafe "windows.h GetModuleFileNameW"
62-
c_GetModuleFileName :: HMODULE -> LPTSTR -> Int -> IO Bool
6354

6455
getModuleHandle :: Maybe String -> IO HMODULE
6556
getModuleHandle mb_name =
6657
maybeWith withTString mb_name $ \ c_name ->
6758
failIfNull "GetModuleHandle" $ c_GetModuleHandle c_name
68-
foreign import WINDOWS_CCONV unsafe "windows.h GetModuleHandleW"
69-
c_GetModuleHandle :: LPCTSTR -> IO HMODULE
7059

7160
getProcAddress :: HMODULE -> String -> IO Addr
7261
getProcAddress hmod procname =
7362
withCAString procname $ \ c_procname ->
7463
failIfNull "GetProcAddress" $ c_GetProcAddress hmod c_procname
7564

76-
foreign import WINDOWS_CCONV unsafe "windows.h GetProcAddress"
77-
c_GetProcAddress :: HMODULE -> LPCSTR -> IO Addr
78-
7965
loadLibrary :: String -> IO HINSTANCE
8066
loadLibrary name =
8167
withTString name $ \ c_name ->
8268
failIfNull "LoadLibrary" $ c_LoadLibrary c_name
83-
foreign import WINDOWS_CCONV unsafe "windows.h LoadLibraryW"
84-
c_LoadLibrary :: LPCTSTR -> IO HINSTANCE
85-
86-
type LoadLibraryFlags = DWORD
87-
88-
#{enum LoadLibraryFlags,
89-
, lOAD_LIBRARY_AS_DATAFILE = LOAD_LIBRARY_AS_DATAFILE
90-
, lOAD_WITH_ALTERED_SEARCH_PATH = LOAD_WITH_ALTERED_SEARCH_PATH
91-
}
9269

9370
loadLibraryEx :: String -> HANDLE -> LoadLibraryFlags -> IO HINSTANCE
9471
loadLibraryEx name h flags =
9572
withTString name $ \ c_name ->
9673
failIfNull "LoadLibraryEx" $ c_LoadLibraryEx c_name h flags
97-
foreign import WINDOWS_CCONV unsafe "windows.h LoadLibraryExW"
98-
c_LoadLibraryEx :: LPCTSTR -> HANDLE -> LoadLibraryFlags -> IO HINSTANCE
9974

10075
setDllDirectory :: Maybe String -> IO ()
10176
setDllDirectory name =
10277
maybeWith withTString name $ \ c_name ->
10378
failIfFalse_ (unwords ["SetDllDirectory", fromMaybe "NULL" name]) $ c_SetDllDirectory c_name
10479

105-
foreign import WINDOWS_CCONV unsafe "windows.h SetDllDirectoryW"
106-
c_SetDllDirectory :: LPTSTR -> IO BOOL

System/Win32/DLL/Internal.hsc

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#if __GLASGOW_HASKELL__ >= 709
2+
{-# LANGUAGE Safe #-}
3+
#else
4+
{-# LANGUAGE Trustworthy #-}
5+
#endif
6+
-----------------------------------------------------------------------------
7+
-- |
8+
-- Module : System.Win32.DLL.Internal
9+
-- Copyright : (c) Alastair Reid, 1997-2003
10+
-- License : BSD-style (see the file libraries/base/LICENSE)
11+
--
12+
-- Maintainer : Esa Ilari Vuokko <[email protected]>
13+
-- Stability : provisional
14+
-- Portability : portable
15+
--
16+
-- A collection of FFI declarations for interfacing with Win32.
17+
--
18+
-----------------------------------------------------------------------------
19+
20+
module System.Win32.DLL.Internal where
21+
22+
import System.Win32.Types
23+
24+
##include "windows_cconv.h"
25+
26+
#include <windows.h>
27+
28+
foreign import WINDOWS_CCONV unsafe "windows.h DisableThreadLibraryCalls"
29+
c_DisableThreadLibraryCalls :: HMODULE -> IO Bool
30+
31+
foreign import WINDOWS_CCONV unsafe "windows.h FreeLibrary"
32+
c_FreeLibrary :: HMODULE -> IO Bool
33+
34+
foreign import WINDOWS_CCONV unsafe "windows.h GetModuleFileNameW"
35+
c_GetModuleFileName :: HMODULE -> LPTSTR -> Int -> IO Bool
36+
37+
foreign import WINDOWS_CCONV unsafe "windows.h GetModuleHandleW"
38+
c_GetModuleHandle :: LPCTSTR -> IO HMODULE
39+
40+
foreign import WINDOWS_CCONV unsafe "windows.h GetProcAddress"
41+
c_GetProcAddress :: HMODULE -> LPCSTR -> IO Addr
42+
43+
foreign import WINDOWS_CCONV unsafe "windows.h LoadLibraryW"
44+
c_LoadLibrary :: LPCTSTR -> IO HINSTANCE
45+
46+
type LoadLibraryFlags = DWORD
47+
48+
#{enum LoadLibraryFlags,
49+
, lOAD_LIBRARY_AS_DATAFILE = LOAD_LIBRARY_AS_DATAFILE
50+
, lOAD_WITH_ALTERED_SEARCH_PATH = LOAD_WITH_ALTERED_SEARCH_PATH
51+
}
52+
53+
foreign import WINDOWS_CCONV unsafe "windows.h LoadLibraryExW"
54+
c_LoadLibraryEx :: LPCTSTR -> HANDLE -> LoadLibraryFlags -> IO HINSTANCE
55+
56+
foreign import WINDOWS_CCONV unsafe "windows.h SetDllDirectoryW"
57+
c_SetDllDirectory :: LPTSTR -> IO BOOL

System/Win32/DebugApi.hsc

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,18 @@ module System.Win32.DebugApi
7070
, outputDebugString
7171
) where
7272

73+
import System.Win32.DebugApi.Internal
7374
import Control.Exception( bracket_ )
74-
import Data.Word ( Word8, Word32 )
7575
import Foreign ( Ptr, nullPtr, ForeignPtr, mallocForeignPtrBytes
7676
, peekByteOff, plusPtr, allocaBytes, castPtr, poke
7777
, withForeignPtr, Storable, sizeOf, peek, pokeByteOff )
7878
import System.IO ( fixIO )
79-
import System.Win32.Types ( HANDLE, BOOL, WORD, DWORD, failIf_, failWith
80-
, getLastError, failIf, LPTSTR, withTString )
79+
import System.Win32.Types ( WORD, DWORD, failIf_, failWith
80+
, getLastError, failIf, withTString )
8181

8282
##include "windows_cconv.h"
8383
#include "windows.h"
8484

85-
type PID = DWORD
86-
type TID = DWORD
87-
type DebugEventId = (PID, TID)
88-
type ForeignAddress = Word32
89-
90-
type PHANDLE = Ptr ()
91-
type THANDLE = Ptr ()
92-
93-
type ThreadInfo = (THANDLE, ForeignAddress, ForeignAddress) -- handle to thread, thread local, thread start
94-
type ImageInfo = (HANDLE, ForeignAddress, DWORD, DWORD, ForeignAddress)
95-
type ExceptionInfo = (Bool, Bool, ForeignAddress) -- First chance, continuable, address
9685

9786

9887
data Exception
@@ -416,48 +405,3 @@ modifyThreadContext t a = withThreadContext t $ makeModThreadContext a
416405
outputDebugString :: String -> IO ()
417406
outputDebugString s = withTString s $ \c_s -> c_OutputDebugString c_s
418407

419-
--------------------------------------------------------------------------
420-
-- Raw imports
421-
422-
foreign import WINDOWS_CCONV "windows.h SuspendThread"
423-
c_SuspendThread :: THANDLE -> IO DWORD
424-
425-
foreign import WINDOWS_CCONV "windows.h ResumeThread"
426-
c_ResumeThread :: THANDLE -> IO DWORD
427-
428-
foreign import WINDOWS_CCONV "windows.h WaitForDebugEvent"
429-
c_WaitForDebugEvent :: Ptr () -> DWORD -> IO BOOL
430-
431-
foreign import WINDOWS_CCONV "windows.h ContinueDebugEvent"
432-
c_ContinueDebugEvent :: DWORD -> DWORD -> DWORD -> IO BOOL
433-
434-
foreign import WINDOWS_CCONV "windows.h DebugActiveProcess"
435-
c_DebugActiveProcess :: DWORD -> IO Bool
436-
437-
-- Windows XP
438-
-- foreign import WINDOWS_CCONV "windows.h DebugActiveProcessStop"
439-
-- c_DebugActiveProcessStop :: DWORD -> IO Bool
440-
441-
foreign import WINDOWS_CCONV "windows.h ReadProcessMemory" c_ReadProcessMemory ::
442-
PHANDLE -> Ptr () -> Ptr Word8 -> DWORD -> Ptr DWORD -> IO BOOL
443-
444-
foreign import WINDOWS_CCONV "windows.h WriteProcessMemory" c_WriteProcessMemory ::
445-
PHANDLE -> Ptr () -> Ptr Word8 -> DWORD -> Ptr DWORD -> IO BOOL
446-
447-
foreign import WINDOWS_CCONV "windows.h GetThreadContext"
448-
c_GetThreadContext :: THANDLE -> Ptr () -> IO BOOL
449-
450-
foreign import WINDOWS_CCONV "windows.h SetThreadContext"
451-
c_SetThreadContext :: THANDLE -> Ptr () -> IO BOOL
452-
453-
--foreign import WINDOWS_CCONV "windows.h GetThreadId"
454-
-- c_GetThreadId :: THANDLE -> IO TID
455-
456-
foreign import WINDOWS_CCONV "windows.h OutputDebugStringW"
457-
c_OutputDebugString :: LPTSTR -> IO ()
458-
459-
foreign import WINDOWS_CCONV "windows.h IsDebuggerPresent"
460-
isDebuggerPresent :: IO BOOL
461-
462-
foreign import WINDOWS_CCONV "windows.h DebugBreak"
463-
debugBreak :: IO ()

System/Win32/DebugApi/Internal.hsc

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
-----------------------------------------------------------------------------
2+
-- |
3+
-- Module : System.Win32.WindowsString.DebugApi.Internal
4+
-- Copyright : (c) Esa Ilari Vuokko, 2006
5+
-- License : BSD-style (see the file LICENSE)
6+
--
7+
-- Maintainer : Esa Ilari Vuokko <[email protected]>
8+
-- Stability : provisional
9+
-- Portability : portable
10+
--
11+
-- A collection of FFI declarations for using Windows DebugApi.
12+
--
13+
-----------------------------------------------------------------------------
14+
15+
module System.Win32.DebugApi.Internal where
16+
17+
import Data.Word ( Word8, Word32 )
18+
import Foreign ( Ptr )
19+
import System.Win32.Types ( BOOL, DWORD, HANDLE, LPTSTR )
20+
21+
##include "windows_cconv.h"
22+
#include "windows.h"
23+
24+
type PID = DWORD
25+
type TID = DWORD
26+
type DebugEventId = (PID, TID)
27+
type ForeignAddress = Word32
28+
29+
type PHANDLE = Ptr ()
30+
type THANDLE = Ptr ()
31+
32+
type ThreadInfo = (THANDLE, ForeignAddress, ForeignAddress) -- handle to thread, thread local, thread start
33+
type ImageInfo = (HANDLE, ForeignAddress, DWORD, DWORD, ForeignAddress)
34+
type ExceptionInfo = (Bool, Bool, ForeignAddress) -- First chance, continuable, address
35+
36+
--------------------------------------------------------------------------
37+
-- Raw imports
38+
39+
foreign import WINDOWS_CCONV "windows.h SuspendThread"
40+
c_SuspendThread :: THANDLE -> IO DWORD
41+
42+
foreign import WINDOWS_CCONV "windows.h ResumeThread"
43+
c_ResumeThread :: THANDLE -> IO DWORD
44+
45+
foreign import WINDOWS_CCONV "windows.h WaitForDebugEvent"
46+
c_WaitForDebugEvent :: Ptr () -> DWORD -> IO BOOL
47+
48+
foreign import WINDOWS_CCONV "windows.h ContinueDebugEvent"
49+
c_ContinueDebugEvent :: DWORD -> DWORD -> DWORD -> IO BOOL
50+
51+
foreign import WINDOWS_CCONV "windows.h DebugActiveProcess"
52+
c_DebugActiveProcess :: DWORD -> IO Bool
53+
54+
-- Windows XP
55+
-- foreign import WINDOWS_CCONV "windows.h DebugActiveProcessStop"
56+
-- c_DebugActiveProcessStop :: DWORD -> IO Bool
57+
58+
foreign import WINDOWS_CCONV "windows.h ReadProcessMemory" c_ReadProcessMemory ::
59+
PHANDLE -> Ptr () -> Ptr Word8 -> DWORD -> Ptr DWORD -> IO BOOL
60+
61+
foreign import WINDOWS_CCONV "windows.h WriteProcessMemory" c_WriteProcessMemory ::
62+
PHANDLE -> Ptr () -> Ptr Word8 -> DWORD -> Ptr DWORD -> IO BOOL
63+
64+
foreign import WINDOWS_CCONV "windows.h GetThreadContext"
65+
c_GetThreadContext :: THANDLE -> Ptr () -> IO BOOL
66+
67+
foreign import WINDOWS_CCONV "windows.h SetThreadContext"
68+
c_SetThreadContext :: THANDLE -> Ptr () -> IO BOOL
69+
70+
--foreign import WINDOWS_CCONV "windows.h GetThreadId"
71+
-- c_GetThreadId :: THANDLE -> IO TID
72+
73+
foreign import WINDOWS_CCONV "windows.h OutputDebugStringW"
74+
c_OutputDebugString :: LPTSTR -> IO ()
75+
76+
foreign import WINDOWS_CCONV "windows.h IsDebuggerPresent"
77+
isDebuggerPresent :: IO BOOL
78+
79+
foreign import WINDOWS_CCONV "windows.h DebugBreak"
80+
debugBreak :: IO ()

0 commit comments

Comments
 (0)