2009年3月5日木曜日

Win32APIでDLLの関数を呼ぶ

DLL
extern "C" {
struct P3 {
char* a;
char* b;
wchar_t* c;
};

void __declspec(dllexport) study2(P3* ptr)
{
ptr = ptr;
ptr->c[0] = L'希';
}
}
Ruby
#!/usr/local/bin/ruby -Ku
# -*- encoding: utf-8 -*-
require 'Win32API'
require 'nkf'

def sjis(x)
NKF.nkf('-m0 --ic=utf8 --oc=cp932', x)
end

def utf16le(x)
NKF.nkf('-m0 --ic=utf8 --oc=utf-16le', x)
end

fn_study2 = Win32API.new('Study.dll', 'study2', %w(p), 'v')
x = [ sjis("hello"), sjis("world"), utf16le("あかさた") ]
fn_study2.call(x.pack("ppp"))
puts(NKF.nkf('-m0 --ic=utf-16le --oc=cp932', x[2]))

0 件のコメント:

コメントを投稿