-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadAPI.rb
More file actions
149 lines (122 loc) · 4.36 KB
/
loadAPI.rb
File metadata and controls
149 lines (122 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
require 'fiddle\import'
module WinAPI
extend Fiddle::Importer
dlload 'C:\Windows\System32\user32.dll', 'C:\Windows\System32\kernel32.dll',
'C:\Windows\System32\gdi32.dll'
typealias('HANDLE', 'void*')
typealias('HINSTANCE', 'HANDLE')
typealias('HMODULE', 'HINSTANCE')
typealias('HWND', 'HANDLE')
typealias('LPWSTR', 'unsigned short*') # 16 bit expected
typealias('BOOL', 'int') # dependent on environment
typealias('BYTE', 'unsigned char') # 8 bit expected
typealias('WORD', 'unsigned short') # 16 bit expected
typealias('DWORD', 'unsigned long') # 32 bit expected
typealias('UINT', 'unsigned int') # dependent on environment
typealias('INT_PTR', Fiddle::SIZEOF_VOIDP == 8 ? 'long long' : 'long')
typealias('UINT_PTR', 'unsigned ' + (Fiddle::SIZEOF_VOIDP == 8 ? 'long long' : 'long'))
typealias('LONG_PTR', 'INT_PTR')
typealias('WPARAM', 'UINT_PTR')
typealias('LPARAM', 'LONG_PTR')
typealias('LRESULT', 'LONG_PTR')
typealias('LPSTARTUPINFO', 'void*')
typealias('ATOM', 'WORD')
typealias('WNDCLASSEX*', 'void*')
typealias('WNDPROC', 'LRESULT*')
# Kernel32.dll
extern('HMODULE GetModuleHandle(LPWSTR)')
extern('void GetStartupInfo(LPSTARTUPINFO*)')
# User32.dll
extern('int MessageBoxW(HWND, LPWSTR, LPWSTR, UINT)')
extern('ATOM RegisterClassExW(WNDCLASSEX*)')
extern('void* CreateWindowExW(DWORD, LPWSTR, LPWSTR, DWORD, int, int, int, int, HWND, HANDLE, HINSTANCE, void*)')
extern('BOOL ShowWindow(HWND, int)')
extern('HANDLE LoadIconW(HINSTANCE, LPWSTR)')
extern('HANDLE LoadCursorW(HINSTANCE, LPWSTR)')
extern('BOOL GetClassInfoW(HINSTANCE, LPWSTR, WNDCLASSEX*)')
extern('HANDLE LoadImageW(HINSTANCE, LPWSTR, UINT, int, int, UINT)') # will replace LoadIcon and LoadCursor
# Gdi32.dll
extern('HANDLE GetStockObject(int)')
def self.DefWindowProcW(*args)
func = Fiddle::Function.new(import_symbol('DefWindowProcW'),
[Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_UINTPTR_T, Fiddle::TYPE_INTPTR_T], Fiddle::TYPE_INTPTR_T)
if args.length == 0 then func.ptr
else func.call(*args) end
end
StartupInfo = struct([
'DWORD cb',
'LPWSTR lpReserved',
'LPWSTR lpDesktop',
'LPWSTR lpTitle',
'DWORD dwX',
'DWORD dwY',
'DWORD dwXSize',
'DWORD dwYSize',
'DWORD dwXCountChars',
'DWORD dwYCountChars',
'DWORD dwFillAttribute',
'DWORD dwFlags',
'WORD wShowWindow',
'WORD cbReserved2',
'BYTE* lpReserved2',
'HANDLE hStdInput',
'HANDLE hStdOutput',
'HANDLE hStdError'
])
WndClassEx = struct([
'UINT cbSize',
'UINT style',
'WNDPROC lpfnWndProc',
'int cbClsExtra',
'int cbWndExtra',
'HINSTANCE hInstance',
'HANDLE hIcon',
'HANDLE hCursor',
'HANDLE hbrBackground',
'LPWSTR lpszMenuName',
'LPWSTR lpszClassName',
'HANDLE hIconSm'
])
module Constants
def self.MAKEINTRESOURCE(int)
Fiddle::Pointer.to_ptr(int)
end
HInstance = WinAPI.GetModuleHandle(nil)
WS_OVERLAPPED = 0x0000_0000
WS_CAPTION = 0x00C0_0000
WS_SYSMENU = 0x0008_0000
WS_THICKFRAME = 0x0004_0000
WS_MINIMIZEBOX = 0x0002_0000
WS_MAXIMIZEBOX = 0x0001_0000
WS_OVERLAPPEDWINDOW = WS_OVERLAPPED |
WS_CAPTION |
WS_SYSMENU |
WS_THICKFRAME |
WS_MINIMIZEBOX |
WS_MAXIMIZEBOX
CW_USEDEFAULT = -0x8000_0000
CS_VREDRAW = 0x0001
CS_HREDRAW = 0x0002
IDI_APPLICATION = MAKEINTRESOURCE(0x7f00)
IDC_ARROW = MAKEINTRESOURCE(0x7f00)
WHITE_BRUSH = 0
end
end
class Fiddle::CStruct
def self.malloc(&proc)
proc ||= Proc.new{}
proc.call(super)
end
end
class String
def wchar_t()
self.encode(Encoding::UTF_16LE)
end
end
def TEXT(str)
if str.kind_of?(String)
str.encode(Encoding::UTF_16LE)
else
raise TypeError
end
end