Created
December 30, 2014 13:21
-
-
Save Youka/3ebbdfd03454afa7d0c4 to your computer and use it in GitHub Desktop.
Simple use of ruby's fiddle library for windows messageboxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load importer part of fiddle (ffi) library | |
require 'fiddle/import' | |
# Create module as body for an importer instance | |
module MessageBox | |
# Extend this module to an importer | |
extend Fiddle::Importer | |
# Load 'user32' dynamic library into this importer | |
dlload 'user32' | |
# Set C aliases to this importer for further understanding of function signatures | |
typealias 'HANDLE', 'void*' | |
typealias 'HWND', 'HANDLE' | |
typealias 'LPCSTR', 'const char*' | |
typealias 'LPCWSTR', 'const wchar_t*' | |
typealias 'UINT', 'unsigned int' | |
# Import C functions from loaded libraries and set them as module functions | |
extern 'int MessageBoxA(HWND, LPCSTR, LPCSTR, UINT)' | |
extern 'int MessageBoxW(HWND, LPCWSTR, LPCWSTR, UINT)' | |
end | |
# Tests | |
MessageBox::MessageBoxA nil, "Hello world!の", "Fiddle ANSI", 0 | |
MessageBox::MessageBoxW nil, "Hello world!の".encode("utf-16le"), "Fiddle WIDECHAR".encode("utf-16le"), 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment