Hi Julians,
I am trying to implement a script that will list all Fonts installed on Windows using Gdi32.dll.
First of all, here is the full script so you can make sense of what i’m about to write below: https://github.com/gabrielfreire/Fonts/blob/master/fonts.jl
All my C calls are working fine,
my problem is that when i receive ENUMLOGFONTA in the callback i pass to EnumFontFamiliesW
and try to unsafe_string
the lplf.elfFullName
property it throws an EXCEPTION_ACCESS_VIOLATION
exception, even though i am using Ref{ENUMLOGFONTA}
to declare my callback @cfunction
, i’m not sure if i understood the documentation correctly, but i believe Ref
is supposed to avoid C from freeing that pointer and let me load it later, right?
same happens for lplf.elfLogFont.lfFaceName
.
function enum_fam_callback(lplf::ENUMLOGFONTA, lpntm::NEWTEXTMETRICA, font_type::DWORD, afont_count::LPARAM)
# Store true type fonts
if Int32(font_type) == FontType.TrueType
if lplf != C_NULL
font = Dict(
"name"=>unsafe_string(lplf.elfFullName), # this throws EXCEPTION_ACCESS_VIOLATION
"quality"=>lplf.elfLogFont.lfQuality,
"weight"=>lplf.elfLogFont.lfWeight,
"faceName"=>lplf.elfLogFont.lfFaceName,
"fontPitchAndFamily"=>lplf.elfLogFont.lfPitchAndFamily,
"charSet"=>lplf.elfLogFont.lfCharSet
)
push!(fontnames, font)
end
end
# dump(lplf)
return convert(Cint, 1)::Cint
end
My Julia struct
struct LOGFONTA
lfHeight::Clong
lfWidth::Clong
lfEscapement::Clong
lfOrientation::Clong
lfWeight::Clong
lfItalic::UInt8
lfUnderline::UInt8
lfStrikeOut::UInt8
lfCharSet::UInt8
lfOutPrecision::UInt8
lfClipPrecision::UInt8
lfQuality::UInt8
lfPitchAndFamily::UInt8
lfFaceName::Cstring
end
struct ENUMLOGFONTA
elfLogFont::LOGFONTA
elfFullName::Cstring
elfStyle::Cstring
end
Windows API C++ struct
typedef struct tagLOGFONTA {
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;
CHAR lfFaceName[LF_FACESIZE];
} LOGFONTA, *PLOGFONTA, *NPLOGFONTA, *LPLOGFONTA;
typedef struct tagENUMLOGFONTA {
LOGFONTA elfLogFont;
BYTE elfFullName[LF_FULLFACESIZE];
BYTE elfStyle[LF_FACESIZE];
} ENUMLOGFONTA, *LPENUMLOGFONTA;
I am pretty sure i am doing something wrong, but i can’t find where.
Please, help.
Full error message
Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x7ffeb535d4e0 -- strlen at C:\Windows\System32\msvcrt.dll (unknown line)
in expression starting at C:\Users\gabrielfreiredev\Documents\workspace\Fonts\fonts.jl:158
strlen at C:\Windows\System32\msvcrt.dll (unknown line)
jl_cstr_to_string at /home/Administrator/buildbot/worker/package_win64/build/src/home/Administrator/buildbot/worker/package_win64/build/src\array.c:496
unsafe_string at .\strings\string.jl:57 [inlined]
unsafe_string at .\c.jl:193 [inlined]
enum_fam_callback at C:\Users\gabrielfreiredev\Documents\workspace\Fonts\fonts.jl:134
unknown function (ip: 000000002936C362)
EnumFontFamiliesExW at C:\Windows\System32\gdi32full.dll (unknown line)
EnumFontFamiliesW at C:\Windows\System32\gdi32full.dll (unknown line)
top-level scope at C:\Users\gabrielfreiredev\Documents\workspace\Fonts\fonts.jl:158
jl_toplevel_eval_flex at /home/Administrator/buildbot/worker/package_win64/build/src/home/Administrator/buildbot/worker/package_win64/build/src\toplevel.c:808
jl_parse_eval_all at /home/Administrator/buildbot/worker/package_win64/build/src/home/Administrator/buildbot/worker/package_win64/build/src\ast.c:873
jl_load at /home/Administrator/buildbot/worker/package_win64/build/src/home/Administrator/buildbot/worker/package_win64/build/src\toplevel.c:878 [inlined]
jl_load_ at /home/Administrator/buildbot/worker/package_win64/build/src/home/Administrator/buildbot/worker/package_win64/build/src\toplevel.c:885
include at .\boot.jl:328 [inlined]
include_relative at .\loading.jl:1094
include at .\Base.jl:31
_jl_invoke at /home/Administrator/buildbot/worker/package_win64/build/src/home/Administrator/buildbot/worker/package_win64/build/src\gf.c:2043 [inlined]
jl_apply_generic at /home/Administrator/buildbot/worker/package_win64/build/src/home/Administrator/buildbot/worker/package_win64/build/src\gf.c:2213
exec_options at .\client.jl:295
_start at .\client.jl:464
_jl_invoke at /home/Administrator/buildbot/worker/package_win64/build/src/home/Administrator/buildbot/worker/package_win64/build/src\gf.c:2043 [inlined]
jl_apply_generic at /home/Administrator/buildbot/worker/package_win64/build/src/home/Administrator/buildbot/worker/package_win64/build/src\gf.c:2213
jl_apply at /home/Administrator/buildbot/worker/package_win64/build/ui/home/Administrator/buildbot/worker/package_win64/build/src\julia.h:1624 [inlined]
true_main at /home/Administrator/buildbot/worker/package_win64/build/ui/home/Administrator/buildbot/worker/package_win64/build/ui\repl.c:96
wmain at /home/Administrator/buildbot/worker/package_win64/build/ui/home/Administrator/buildbot/worker/package_win64/build/ui\repl.c:217
__tmainCRTStartup at /usr/src/debug/mingw64-x86_64-runtime-6.0.0-1/usr/src/debug/mingw64-x86_64-runtime-6.0.0-1/crt\crtexe.c:334
mainCRTStartup at /usr/src/debug/mingw64-x86_64-runtime-6.0.0-1/usr/src/debug/mingw64-x86_64-runtime-6.0.0-1/crt\crtexe.c:223
BaseThreadInitThunk at C:\Windows\System32\KERNEL32.DLL (unknown line)
RtlUserThreadStart at C:\Windows\SYSTEM32\ntdll.dll (unknown line)
Allocations: 2732207 (Pool: 2731174; Big: 1033); GC: 5
Thank you.