LUA调用Windows下的DLL有两个方法。Alien与LUA LIB库编译。

Alien方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'alien'
local user = alien.load 'user32.dll'
 
-- these are the API calls needed. Note two NB things:
-- (1) functions dealing with text ending with 'A' are for ASCII
-- (2) need to specify abi to get proper __stdcall
user.FindWindowA:types {"string","string",abi="stdcall"}
user.GetWindowTextA:types {"int","string","int",abi="stdcall"}
user.GetClassNameA:types{"int","string","int",abi="stdcall"}
 
find = user.FindWindowA
gettext = user.GetWindowTextA
getclass = user.GetClassNameA
 
local mydll = alien.load "MyLuaDLL.dll"
mydll.callme:types{"int","string","int",abi="stdcall"}
callme = mydll.callme
 
t1 = alien.buffer(50)
callme(2, t1, 50);
print("callme=".. t1:tostring());

LUA LIB库编译方法

Continue reading »

© 2012 客家缘分小筑 Suffusion theme by Sayontan Sinha