import windows
var callback = proc(logfont:var ENUMLOGFONTEX,
metric:var NEWTEXTMETRICEX,
fontTp:int32, lparam:LPARAM):int32 =
echo("enumed font=",repr(logfont))
return 1 # continue enumeration
(proc () =
var logf:LOGFONT
logf.lfCharSet = DEFAULT_CHARSET
logf.lfFaceName[0] = 0.char
logf.lfPitchAndFamily = 0
discard EnumFontFamiliesEx(0.HDC,addr logf,
callback.FONTENUMEXPROC,0.LPARAM,0.DWORD)
)()
But compiling (well, under wine on a linux box) gives the error:
conversion from proc (logfont: var ENUMLOGFONTEX,
metric: var NEWTEXTMETRICEX, fontTp: int32, lparam: LPARAM): int32
{.gcsafe, locks: 0.} to FONTENUMEXPROC is invalid
although the windows.nim declaration for FONTENUMEXPROC is:
FONTENUMEXPROC* = proc (para1: var ENUMLOGFONTEX,
para2: var NEWTEXTMETRICEX,
para3: int32, para4: LPARAM): int32{.stdcall.}
Are the pragmas gcsafe and locks:0 the problem??? If so, how do I remove them (since they are compiler generated)
Add {.stdcall.} to your proc:
var callback = proc(logfont:var ENUMLOGFONTEX,
metric:var NEWTEXTMETRICEX,
fontTp:int32, lparam:LPARAM):int32 {.stdcall.} =
echo("enumed font=",repr(logfont))
return 1 # continue enumeration
(untested)That did the trick - no more compiler error. THANKS.
The app still doesn't list fonts (even on an actual MS Windows box) - but that is a question for a different forum, I guess.
Anyway - many thanks.