Skip to content

Commit 78ccf91

Browse files
authoredJan 2, 2018
Remove c/winapi and rename some windows types (#5448)
winapi.cr used old and outdated conventions regarding the windows porting effort. It is deleted, and the definitions in it which are used are moved to files corresponding to the windows header they are defined in. Some windows types are also renamed to retain their capitalisation from Microsoft's headers.
1 parent f6e7c2e commit 78ccf91

File tree

5 files changed

+26
-241
lines changed

5 files changed

+26
-241
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lib LibC
2+
alias DWORD = UInt32
3+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lib LibC
2+
alias LPSTR = Char*
3+
end

‎src/lib_c/x86_64-windows-msvc/c/winapi.cr

-239
This file was deleted.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require "c/win_nt"
2+
require "c/int_safe"
3+
4+
lib LibC
5+
fun GetLastError : DWORD
6+
7+
FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100_u32
8+
FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200_u32
9+
FORMAT_MESSAGE_FROM_STRING = 0x00000400_u32
10+
FORMAT_MESSAGE_FROM_HMODULE = 0x00000800_u32
11+
FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000_u32
12+
FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000_u32
13+
14+
fun FormatMessageA(dwFlags : DWORD, lpSource : Void*, dwMessageId : DWORD, dwLanguageId : DWORD,
15+
lpBuffer : LPSTR, nSize : DWORD, arguments : Void*) : DWORD
16+
end

‎src/winerror.cr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
require "c/winbase"
2+
13
class WinError < Errno
24
# NOTE: `get_last_error` must be called BEFORE an instance of this class
35
# is malloced as it would change the "last error" to SUCCESS
46
def self.new(message)
5-
new(message, LibC._GetLastError)
7+
new(message, LibC.GetLastError)
68
end
79

810
def initialize(message, code)
911
buffer = uninitialized UInt8[256]
10-
size = LibC._FormatMessageA(LibC::FORMAT_MESSAGE_FROM_SYSTEM, nil, code, 0, buffer, buffer.size, nil)
12+
size = LibC.FormatMessageA(LibC::FORMAT_MESSAGE_FROM_SYSTEM, nil, code, 0, buffer, buffer.size, nil)
1113
details = String.new(buffer.to_unsafe, size).strip
1214
super("#{message}: [WinError #{code}, #{details}]", winerror_to_errno(code))
1315
end

0 commit comments

Comments
 (0)
Please sign in to comment.