本文整理汇总了C#中PropVariant类的典型用法代码示例。如果您正苦于以下问题:C# PropVariant类的具体用法?C# PropVariant怎么用?C# PropVariant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PropVariant类属于命名空间,在下文中一共展示了PropVariant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromPropVariant
public static ManagedPropVariant FromPropVariant(PropVariant propVariant)
{
// Do a bitwise copy from the PropVariant that was passed in.
ManagedPropVariant managedPropVariant = new ManagedPropVariant();
UnsafeNativeMethods.CopyFromPropVariant(out managedPropVariant, ref propVariant);
return managedPropVariant;
}
示例2: CreateLeafCondition
/// <summary>
/// Creates a leaf condition node that represents a comparison of property value and constant value.
/// </summary>
/// <param name="propertyName">The name of a property to be compared, or null for an unspecified property.
/// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
/// <param name="value">The constant value against which the property value should be compared.</param>
/// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
/// <returns>SearchCondition based on the given parameters</returns>
/// <remarks>
/// The search will only work for files that are indexed, as well as the specific properties are indexed. To find
/// the properties that are indexed, look for the specific property's property description and
/// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
/// </remarks>
public static SearchCondition CreateLeafCondition(string propertyName, string value, SearchConditionOperation operation)
{
PropVariant propVar = new PropVariant();
propVar.SetString(value);
return CreateLeafCondition(propertyName, propVar, null, operation);
}
示例3: CreateLeafCondition
/// <summary>
/// Creates a leaf condition node that represents a comparison of property value and constant value.
/// </summary>
/// <param name="propertyName">The name of a property to be compared, or null for an unspecified property.
/// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
/// <param name="value">The constant value against which the property value should be compared.</param>
/// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
/// <returns>SearchCondition based on the given parameters</returns>
/// <remarks>
/// The search will only work for files that are indexed, as well as the specific properties are indexed. To find
/// the properties that are indexed, look for the specific property's property description and
/// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
/// </remarks>
public static SearchCondition CreateLeafCondition(string propertyName, string value, SearchConditionOperation operation)
{
using (PropVariant propVar = new PropVariant(value))
{
return CreateLeafCondition(propertyName, propVar, null, operation);
}
}
示例4: UpdateProperty
public virtual int UpdateProperty(uint commandId, ref PropertyKey key, PropVariantRef currentValue, out PropVariant newValue)
{
Command command = ParentCommandManager.Get((CommandId)commandId);
if (command == null)
{
return NullCommandUpdateProperty(commandId, ref key, currentValue, out newValue);
}
try
{
newValue = new PropVariant();
command.GetPropVariant(key, currentValue, ref newValue);
if (newValue.IsNull())
{
Trace.Fail("Didn't property update property for " + PropertyKeys.GetName(key) + " on command " + ((CommandId)commandId).ToString());
newValue = PropVariant.FromObject(currentValue.PropVariant.Value);
}
}
catch (Exception ex)
{
Trace.Fail("Exception in UpdateProperty for " + PropertyKeys.GetName(key) + " on command " + commandId + ": " + ex);
newValue = PropVariant.FromObject(currentValue.PropVariant.Value);
}
return HRESULT.S_OK;
}
示例5: SearchCondition
internal SearchCondition(ICondition nativeSearchCondition)
{
if (nativeSearchCondition == null)
{
throw new ArgumentNullException("nativeSearchCondition");
}
NativeSearchCondition = nativeSearchCondition;
HResult hr = NativeSearchCondition.GetConditionType(out conditionType);
if (!CoreErrorHelper.Succeeded(hr))
{
throw new ShellException(hr);
}
if (ConditionType == SearchConditionType.Leaf)
{
using (PropVariant propVar = new PropVariant())
{
hr = NativeSearchCondition.GetComparisonInfo(out canonicalName, out conditionOperation, propVar);
if (!CoreErrorHelper.Succeeded(hr))
{
throw new ShellException(hr);
}
PropertyValue = propVar.Value.ToString();
}
}
}
示例6: InstallShortcut
private void InstallShortcut(String shortcutPath)
{
// Find the path to the current executable
String exePath = Process.GetCurrentProcess().MainModule.FileName;
IShellLinkW newShortcut = (IShellLinkW)new CShellLink();
// Create a shortcut to the exe
ShellHelpers.ErrorHelper.VerifySucceeded(newShortcut.SetPath(exePath));
ShellHelpers.ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));
// Open the shortcut property store, set the AppUserModelId property
IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;
using (PropVariant appId = new PropVariant(APP_ID))
{
ShellHelpers.ErrorHelper.VerifySucceeded(
newShortcutProperties.SetValue(SystemProperties.System.AppUserModel.ID, appId));
ShellHelpers.ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());
}
// Commit the shortcut to disk
IPersistFile newShortcutSave = (IPersistFile)newShortcut;
ShellHelpers.ErrorHelper.VerifySucceeded(newShortcutSave.Save(shortcutPath, true));
}
示例7: ToPropVariant
public static PropVariant ToPropVariant(ManagedPropVariant managedPropVariant)
{
// Do a bitwise copy from the ManagedPropVariant that was passed in.
PropVariant propVariant = new PropVariant();
UnsafeNativeMethods.CopyToPropVariant(out propVariant, ref managedPropVariant);
return propVariant;
}
示例8: FromString
public static PropVariant FromString(string str)
{
var pv = new PropVariant() {
variantType = 31, // VT_LPWSTR
pointerValue = Marshal.StringToCoTaskMemUni(str),
};
return pv;
}
示例9: GetPropVariant
public override void GetPropVariant(PropertyKey key, PropVariantRef currentValue, ref PropVariant value)
{
if (key == PropertyKeys.ContextAvailable)
{
value.SetUInt((uint)ContextAvailability);
}
else
base.GetPropVariant(key, currentValue, ref value);
}
示例10: FromObjectNullTest
public void FromObjectNullTest()
{
using (PropVariant pv = new PropVariant())
{
Assert.True(pv.IsNullOrEmpty);
Assert.Equal(VarEnum.VT_EMPTY, pv.VarType);
Assert.Null(pv.Value);
}
}
示例11: SetWindowProperty
internal static void SetWindowProperty(IntPtr hwnd, PropertyKey propkey, string value)
{
// Get the IPropertyStore for the given window handle
IPropertyStore propStore = GetWindowPropertyStore(hwnd);
// Set the value
PropVariant pv = new PropVariant();
propStore.SetValue(ref propkey, ref pv);
// Dispose the IPropertyStore and PropVariant
Marshal.ReleaseComObject(propStore);
pv.Clear();
}
示例12: ListOrExtract
private static void ListOrExtract(string archiveName, uint level)
{
using (SevenZipFormat Format = new SevenZipFormat(SevenZipDllPath))
{
IInArchive Archive = Format.CreateInArchive(SevenZipFormat.GetClassIdFromKnownFormat(KnownSevenZipFormat.Zip));
if (Archive == null)
return;
try
{
using (InStreamWrapper ArchiveStream = new InStreamWrapper(File.OpenRead(archiveName)))
{
IArchiveOpenCallback OpenCallback = new ArchiveOpenCallback();
// 32k CheckPos is not enough for some 7z archive formats
ulong CheckPos = 128 * 1024;
if (Archive.Open(ArchiveStream, ref CheckPos, OpenCallback) != 0)
//ShowHelp();
if (!Directory.Exists(@"tmp_dir"))
Directory.CreateDirectory(@"tmp_dir");
//Console.WriteLine(archiveName);
uint Count = Archive.GetNumberOfItems();
for (uint I = 0; I < Count; I++)
{
PropVariant Name = new PropVariant();
Archive.GetProperty(I, ItemPropId.kpidPath, ref Name);
string FileName = (string)Name.GetObject();
Program.f1.label1.Text = FileName;
Application.DoEvents();
for(int i = 0; i < level; i++)
Console.Write("\t");
Console.Write(FileName + "\n");
FileName += level;
Archive.Extract(new uint[] { I }, 1, 0, new ArchiveExtractCallback(I, FileName));
Program.Determine_Parser(new System.IO.FileInfo("tmp_dir//" + FileName), level);
}
}
}
finally
{
Marshal.ReleaseComObject(Archive);
Directory.Delete(@"tmp_dir", true);
}
}
}
示例13: GetValue
public HRESULT GetValue(ref PropertyKey key, out PropVariant value)
{
if (key == RibbonProperties.Label)
{
if ((_label == null) || (_label.Trim() == string.Empty))
{
value = PropVariant.Empty;
}
else
{
value = PropVariant.FromObject(_label);
}
return HRESULT.S_OK;
}
if (key == RibbonProperties.LabelDescription)
{
if ((_labelDescription == null) || (_labelDescription.Trim() == string.Empty))
{
value = PropVariant.Empty;
}
else
{
value = PropVariant.FromObject(_labelDescription);
}
return HRESULT.S_OK;
}
if (key == RibbonProperties.Pinned)
{
if (_pinned.HasValue)
{
value = PropVariant.FromObject(_pinned.Value);
}
else
{
value = PropVariant.Empty;
}
return HRESULT.S_OK;
}
Debug.WriteLine(string.Format("Class {0} does not support property: {1}.", GetType().ToString(), RibbonProperties.GetPropertyKeyName(ref key)));
value = PropVariant.Empty;
return HRESULT.E_NOTIMPL;
}
示例14: GetValue
public HRESULT GetValue(ref PropertyKey key, out PropVariant value)
{
if (key == RibbonProperties.CommandID)
{
if (_commandID.HasValue)
{
value = PropVariant.FromObject(_commandID.Value);
}
else
{
value = PropVariant.Empty;
}
return HRESULT.S_OK;
}
if (key == RibbonProperties.CommandType)
{
if (_commandType.HasValue)
{
value = PropVariant.FromObject((uint)_commandType.Value);
}
else
{
value = PropVariant.Empty;
}
return HRESULT.S_OK;
}
if (key == RibbonProperties.CategoryID)
{
if (_categoryID.HasValue)
{
value = PropVariant.FromObject(_categoryID.Value);
}
else
{
value = PropVariant.Empty;
}
return HRESULT.S_OK;
}
Debug.WriteLine(string.Format("Class {0} does not support property: {1}.", GetType(), RibbonProperties.GetPropertyKeyName(ref key)));
value = PropVariant.Empty;
return HRESULT.E_NOTIMPL;
}
示例15: CreateImagePropVariant
public static void CreateImagePropVariant(Image image, out PropVariant pv)
{
try
{
pv = new PropVariant();
// Note that the missing image is a 32x32 png.
if (image == null)
image = Images.Missing_LargeImage;
pv.SetIUnknown(CreateImage(((Bitmap)image).GetHbitmap(), ImageCreationOptions.Transfer));
}
catch (Exception ex)
{
Trace.Fail("Failed to create image PropVariant: " + ex);
pv = new PropVariant();
}
}