【发布时间】:2009-10-30 03:56:31
【问题描述】:
我目前在玩 Lua 和外星人模块以使用 Lua 脚本中的 Win32 API 等时遇到了一个问题。到目前为止,我只遇到过外星人的一个问题,即使用使用某些结构(如 CreateFontIndirect)的 API。
例如:
HFONT CreateFontIndirectA( const LOGFONT& lplf );
LOGFONT:
typedef struct tagLOGFONT {
LONG lfHeight;
LONG lfWidth;
LONG lfEscapement;
LONG lfOrientation;
LONG lfWeight;
BYTE lfItalic;
BYTE lfUnderline;
BYTE lfStrikeOut;
BYTE lfCharSet;
BYTE lfOutPrecision;
BYTE lfClipPrecision;
BYTE lfQuality;
BYTE lfPitchAndFamily;
TCHAR lfFaceName[LF_FACESIZE];
}LOGFONT, *PLOGFONT;
问题在于字体名称。我无法让 Lua 在结构本身中保留一个字符串,它总是将一个指针推入结构中。因此,我无法弄清楚,完全从 Lua 中使用这个 API。
这就是我的工作重点:
LOGFONT = alien.defstruct {
{ 'lfHeight', 'long' },
{ 'lfWidth', 'long' },
{ 'lfEscapement', 'long' },
{ 'lfOrientation', 'long' },
{ 'lfWeight', 'long' },
{ 'lfItalic', 'byte' },
{ 'lfUnderline', 'byte' },
{ 'lfStrikeOut', 'byte' },
{ 'lfCharSet', 'byte' },
{ 'lfOutPrecision', 'byte' },
{ 'lfClipPrecision', 'byte' },
{ 'lfQuality', 'byte' },
{ 'lfPitchAndFamily', 'byte' },
{ 'lfFaceName', 'string' } -- This line isn't working properly.
}
gdi32 = alien.load( "gdi32.dll" )
gdi32.CreateFontIndirectA:types {
ret = 'long',
abi = 'stdcall',
'pointer'
}
举个例子:
local lf = LOGFONT:new()
lf.lfHeight = 14
lf.lfWidth = 0
lf.lfEscapement = 0
lf.lfOrientation = 0
lf.lfWeight = 400
lf.lfItalic = 0
lf.lfUnderline = 0
lf.lfStrikeOut = 0
lf.lfCharSet = 0
lf.lfOutPrecision = 0
lf.lfClipPrecision = 0
lf.lfQuality = 0
lf.lfPitchAndFamily = 0
lf.lfFaceName = 'Terminal'
local hFont = gdi32.CreateFontIndirectA( lf() )
调试运行我的脚本的应用程序表明该 api 被正确调用,所有内容都正确传递,但字体除外。我尝试了各种不同的方法来让它工作,但我不能让它按需要去。
在不将其他任何内容硬编码到 exe 中的情况下解决此问题的任何提示?
【问题讨论】: