Dear all,
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 like:
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
);
My first try in Powershell, but it does not return the font name :
$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)
Yeah, I think you might have more luck on StackOverflow - this is pretty beyond “PowerShell” in terms of what I’m able to help with, at least. This is a lot of layers you’re going through, and I’ve never gotten these kinds of API calls to work well in PowerShell.