lib/windows/unicode.rb in windows-pr-0.6.6 vs lib/windows/unicode.rb in windows-pr-0.7.0
- old
+ new
@@ -1,9 +1,15 @@
-require 'Win32API'
+require 'windows/api'
+include Windows
module Windows
module Unicode
+ API.auto_namespace = 'Windows::Unicode'
+ API.auto_constant = true
+ API.auto_method = true
+ API.auto_unicode = false
+
CP_ACP = 0
CP_OEMCP = 1
CP_MACCP = 2
CP_THREAD_ACP = 3
CP_SYMBOL = 42
@@ -60,52 +66,26 @@
TCI_SRCCHARSET = 1
TCI_SRCCODEPAGE = 2
TCI_SRCFONTSIG = 3
TCI_SRCLOCALE = 0x100
- GetTextCharset = Win32API.new('gdi32', 'GetTextCharset', 'L', 'I')
- GetTextCharsetInfo = Win32API.new('gdi32', 'GetTextCharsetInfo', 'LPL', 'I')
- IsDBCSLeadByte = Win32API.new('kernel32', 'IsDBCSLeadByte', 'P', 'I')
- IsDBCSLeadByteEx = Win32API.new('kernel32', 'IsDBCSLeadByteEx', 'IP', 'I')
- IsTextUnicode = Win32API.new('advapi32', 'IsTextUnicode', 'PIP', 'I')
- MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ILPIPI', 'I')
- TranslateCharsetInfo = Win32API.new('gdi32', 'TranslateCharsetInfo', 'PPL', 'I')
- WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ILPIPIPP', 'I')
+ API.new('GetTextCharset', 'L', 'I', 'gdi32')
+ API.new('GetTextCharsetInfo', 'LPL', 'I', 'gdi32')
+ API.new('IsDBCSLeadByte', 'P', 'B')
+ API.new('IsDBCSLeadByteEx', 'IP', 'B')
+ API.new('IsTextUnicode', 'PIP', 'B', 'advapi32')
+ API.new('MultiByteToWideChar', 'ILPIPI', 'I')
+ API.new('TranslateCharsetInfo', 'PPL', 'B', 'gdi32')
+ API.new('WideCharToMultiByte', 'ILPIPIPP', 'I')
- def GetTextCharset(hdc)
- GetTextCharset.call(hdc)
- end
-
- def GetTextCharsetInfo(hdc, sig, flags)
- GetTextCharsetInfo.call(hdc, sig, flags)
- end
-
- def IsDBCSLeadByte(char)
- IsDBCSLeadByte.call(char) != 0
- end
-
- def IsDBCSLeadByteEx(code_page, char)
- IsDBCSLeadByteEx.call(code_pag, char) != 0
- end
-
- def IsTextUnicode(buf, size = buf.size, options = 0)
- IsTextUnicode.call(buf, size, options) != 0
- end
-
- def MultiByteToWideChar(page, flags, str, str_size, buf, buf_size)
- MultiByteToWideChar.call(page, flags, str, str_size, buf, buf_size)
- end
-
- def TranslateCharsetInfo(src, cs, flags)
- TranslateCharsetInfo.call(src, cs, flags) != 0
- end
-
- def WideCharToMultiByte(page, flags, str, str_size, buf, buf_size, defchar, used_def)
- WideCharToMultiByte.call(page, flags, str, str_size, buf, buf_size, defchar, used_def)
- end
-
# Convenient wrapper methods
+ # Maps a wide character string to a new character string using the
+ # specified +encoding+. If no encoding is specified, then CP_UTF8
+ # iss used if $KCODE is set to UTF8. Otherwise, CP_ACP is used.
+ #
+ # If the function fails it simply returns the string as-is.
+ #
# Maps a string to a wide (unicode) string using +encoding+. If no
# encoding is specified, then CP_UTF8 is used if $KCODE is set to UTF8.
# Otherwise, CP_ACP is used.
#
# If the function fails it simply returns the string as-is.