lpMsgBuf = Ref{Ptr{UInt16}}()
lpMsgBuf[] = 0
len = ccall(:FormatMessageW, stdcall, UInt32, (Cint, Ptr{Cvoid}, Cint, Cint, Ptr{Ptr{UInt16}}, Cint, Ptr{Cvoid}),
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
C_NULL, e, 0, lpMsgBuf, 0, C_NULL)
p = lpMsgBuf[]
len == 0 && return ""
buf = Vector{UInt16}(uninitialized, len)
GC.@preserve buf unsafe_copyto!(pointer(buf), p, len)
ccall(:LocalFree, stdcall, Ptr{Cvoid}, (Ptr{Cvoid},), p)
return transcode(String, buf)
Why is the p
copied to buf
before encoding it?
Why not decode the p
at once?