I have a AutoIt script which uses a undocumented gdi32 function (GetFontResourceInfoW) (Autoit: _WinAPI_GetFontResourceInfo).
It returns the name of a font file (.fon, .ttf, .ttc, etc. installed or not) The script works perfect. I want to recode it now in Powershell. The function prototype (from GetFontResourceInfo) is:
BOOL GetFontResourceInfo(LPCTSTR lpszFilename, // font file name
LPDWORD cbBuffer, // size of buffer for resouce information
LPVOID lpBuffer, // buffer for returned resouce information
DWORD dwQueryType, // resouce information query type
);
I tried the following, but it does not return the fontname.
$code=@'
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
public static class FontUtil{
[DllImport("gdi32.dll")]
public static extern bool GetFontResourceInfoW(string lpszFilename, ref UInt32 cbBuffer, out IntPtr lpBuffer, UInt32 dwQueryType);
}
'@
Add-Type $code
[string]$fn = 'c:\windows\fonts\arial.ttf'
[Uint32]$b = 260
[IntPtr]$LocalStructPtr = Runtime.InteropServices.Marshal]::AllocHGlobal(260)
$ret=[fontutil]::GetFontResourceInfoW($fn, [ref] $b, [ref] $LocalStructPtr,[UInt32]1)
[Runtime.InteropServices.Marshal]::PtrToStringAuto($LocalStructPtr,$b)
[Runtime.InteropServices.Marshal]::FreeHGlobal($LocalStructPtr)
I think there is a problem with the paramaters or interop marshaling.
Any ideas what could be wrong?