[DllImport("kernel32.dll", SetLastError=true)]
public static extern uint PackageFamilyNameFromId( PACKAGE_ID packageId, ref uint packageFamilyNameLength, StringBuilder packageFamilyName );
Call the function with packageFamilyName = NULL to get the required buffer size.
var packageId = new PACKAGE_ID { name = "Package Name", publisher = "CN=MyPublisher" };
uint packageFamilyNameLength = 0;
//First get the length of the Package Name -> Pass NULL as Output Buffer
if ( PackageFamilyNameFromId( packageId, ref packageFamilyNameLength, null ) == 122 ) //ERROR_INSUFFICIENT_BUFFER
{
var packageFamilyNameBuilder = new StringBuilder((int)packageFamilyNameLength);
if ( PackageFamilyNameFromId( packageId, ref packageFamilyNameLength, packageFamilyNameBuilder ) == 0 )
{
Console.WriteLine( "Package Family Name: " + packageFamilyNameBuilder.ToString() );
}
}