/// <summary> /// Gets a list of column names or column-definition-strings for the /// associated view. /// </summary> /// <param name="view">the view to that defines the columns</param> /// <param name="types">true to return types (column definition strings), /// false to return names</param> /// <returns>list of column names or types</returns> private static IList <string> GetViewColumns(View view, bool types) { int recordHandle; int typesFlag = types ? 1 : 0; uint ret = RemotableNativeMethods.MsiViewGetColumnInfo( (int)view.Handle, (uint)typesFlag, out recordHandle); if (ret != 0) { throw InstallerException.ExceptionFromReturnCode(ret); } using (Record rec = new Record((IntPtr)recordHandle, true, null)) { int count = rec.FieldCount; IList <string> columnsList = new List <string>(count); // Since we must be getting all strings of limited length, // this code is faster than calling rec.GetString(field). for (int field = 1; field <= count; field++) { uint bufSize = 256; StringBuilder buf = new StringBuilder((int)bufSize); ret = RemotableNativeMethods.MsiRecordGetString((int)rec.Handle, (uint)field, buf, ref bufSize); if (ret != 0) { throw InstallerException.ExceptionFromReturnCode(ret); } columnsList.Add(buf.ToString()); } return(columnsList); } }
/// <summary> /// Gets a field value as a string. /// </summary> /// <param name="field">Specifies the field to retrieve.</param> /// <returns>String value of the field, or an empty string if the field is null.</returns> /// <exception cref="ArgumentOutOfRangeException">The field is less than 0 or greater than the /// number of fields in the Record.</exception> /// <remarks><p> /// Win32 MSI API: /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msirecordgetstring.asp">MsiRecordGetString</a> /// </p></remarks> public string GetString(int field) { this.CheckRange(field); StringBuilder buf = new StringBuilder(String.Empty); uint bufSize = 0; uint ret = RemotableNativeMethods.MsiRecordGetString((int)this.Handle, (uint)field, buf, ref bufSize); if (ret == (uint)NativeMethods.Error.MORE_DATA) { buf.Capacity = (int)++bufSize; ret = RemotableNativeMethods.MsiRecordGetString((int)this.Handle, (uint)field, buf, ref bufSize); } if (ret != 0) { throw InstallerException.ExceptionFromReturnCode(ret); } return(buf.ToString()); }