i just want to share this piece of code...
sometime you need the correct fontname ,when you use an customfont. There is an undocumented function inside gdi32.dll, which can read the name from the fontfile.
This Code works only on XP systems.
On Win98 systems the gdi function is just called "GetFontResourceInfo". I dont know if it uses unicode strings. and i also dont know it it returns the same structure. Maybe someone on a win98 can figure it out (by debugging fontview.exe)?
sometime you need the correct fontname ,when you use an customfont. There is an undocumented function inside gdi32.dll, which can read the name from the fontfile.
GetFontName proc uses edi esi ebx _fontfile:dword,_buffer:dword,_buffersize:dword
LOCAL local_hlib :DWORD
LOCAL local_fontfile_wide[1024] :BYTE
LOCAL local_sizeof_buffer :DWORD
LOCAL local_fontstruct[92] :BYTE ;unknown structure
;---set return value to 0---
xor ebx,ebx
invoke LoadLibrary,chr$("gdi32.dll")
mov local_hlib,eax
invoke GetProcAddress,eax,chr$("GetFontResourceInfoW")
.if eax!=NULL
mov edi,eax
;---convert ansi to unicode---
invoke MultiByteToWideChar,0,MB_PRECOMPOSED,_fontfile,-1,addr local_fontfile_wide,sizeof local_fontfile_wide
;---add font to Windows font table---
invoke AddFontResource,_fontfile
;---call undocumented GetFontResourceInfoW---
mov local_sizeof_buffer,sizeof local_fontstruct
lea ecx,local_sizeof_buffer
lea eax,local_fontfile_wide
lea esi,local_fontstruct
push 2 ;1=get fontname (works not always good) / 2=get structure with fontname
push esi ;structure
push ecx ;size of recievebuffer
push eax ;font filename
call edi ;GetFontResourceInfoW
.if eax==TRUE
mov ebx,eax ;modify return value to 1
add esi,28 ;point to correct unicode fontname
;---convert unicode to ansi---
invoke WideCharToMultiByte,0,WC_COMPOSITECHECK,esi,-1,_buffer,_buffersize,0,0
.endif
;---remove font from Windows font table---
invoke RemoveFontResource,_fontfile
;---free loaded dll---
invoke FreeLibrary,local_hlib
.endif
mov eax,ebx
ret
GetFontName endp
This Code works only on XP systems.
On Win98 systems the gdi function is just called "GetFontResourceInfo". I dont know if it uses unicode strings. and i also dont know it it returns the same structure. Maybe someone on a win98 can figure it out (by debugging fontview.exe)?