本文整理汇总了C#中IMoniker类的典型用法代码示例。如果您正苦于以下问题:C# IMoniker类的具体用法?C# IMoniker怎么用?C# IMoniker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IMoniker类属于命名空间,在下文中一共展示了IMoniker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetCamera
/// <summary>
/// Initializes camera, builds and runs graph for control.
/// </summary>
/// <param name="moniker">Moniker (device identification) of camera.</param>
/// <param name="resolution">Resolution of camera's output.</param>
public void SetCamera(IMoniker moniker, Resolution resolution)
{
// Close current if it was opened
CloseCamera();
if (moniker == null)
return;
// Create camera object
_Camera = new Camera();
if (!string.IsNullOrEmpty(_DirectShowLogFilepath))
_Camera.DirectShowLogFilepath = _DirectShowLogFilepath;
// select resolution
//ResolutionList resolutions = Camera.GetResolutionList(moniker);
if (resolution != null)
{
_Camera.Resolution = resolution;
}
// Initialize
_Camera.Initialize(this, moniker);
// Build and Run graph
_Camera.BuildGraph();
_Camera.RunGraph();
_Camera.OutputVideoSizeChanged += Camera_OutputVideoSizeChanged;
}
示例2: GetRunningObjectTable
/// <summary>
/// Get a snapshot of the running object table (ROT).
/// </summary>
/// <returns>A hashtable mapping the name of the object
// in the ROT to the corresponding object</returns>
private static Hashtable GetRunningObjectTable()
{
Hashtable result = new Hashtable();
IntPtr numFetched = Marshal.AllocHGlobal(sizeof(int));
IRunningObjectTable runningObjectTable;
IEnumMoniker monikerEnumerator;
IMoniker[] monikers = new IMoniker[1];
GetRunningObjectTable(0, out runningObjectTable);
runningObjectTable.EnumRunning(out monikerEnumerator);
monikerEnumerator.Reset();
while (monikerEnumerator.Next(1, monikers, numFetched) == 0)
{
IBindCtx ctx;
CreateBindCtx(0, out ctx);
string runningObjectName;
monikers[0].GetDisplayName(ctx, null, out runningObjectName);
object runningObjectVal;
runningObjectTable.GetObject(monikers[0], out runningObjectVal);
result[runningObjectName] = runningObjectVal;
}
return result;
}
示例3: GetRunningObjectTableNames
public static List<string> GetRunningObjectTableNames()
{
IRunningObjectTable runningObjectTable;
GetRunningObjectTable(0, out runningObjectTable);
IEnumMoniker monikers;
runningObjectTable.EnumRunning(out monikers);
IMoniker[] moniker = new IMoniker[1];
List<string> names = new List<string>();
monikers.Reset();
int result = 0;
while (result == 0)
{
unsafe
{
int count;
System.IntPtr pCount = (System.IntPtr)(&count);
result = monikers.Next(1, moniker, pCount);
}
if (result != 0)
break;
IBindCtx context;
CreateBindCtx(0, out context);
string name;
moniker[0].GetDisplayName(context, null, out name);
names.Add(name);
}
return names;
}
示例4: GetVisualStudioInstanceBySolution
/// <summary>
/// Search Running Object Table for a running VisualStudio instance which has open a particular solution.
/// Typical usage might be EnvDTE.Solution sln = DesignTime.GetVisualStudioInstanceBySolution(@"\\My Solution\.sln$")
/// </summary>
/// <param name="solution_file_regex">Regular expression matching the solution fullname</param>
/// <returns>The Solution object if a match was found, null otherwise</returns>
public static EnvDTE.Solution GetVisualStudioInstanceBySolution(string solution_file_regex)
{
System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(solution_file_regex);
IRunningObjectTable runningObjectTable;
GetRunningObjectTable(0, out runningObjectTable);
IEnumMoniker monikerEnumerator;
runningObjectTable.EnumRunning(out monikerEnumerator);
monikerEnumerator.Reset();
IMoniker[] monikers = new IMoniker[1];
IntPtr numFetched = IntPtr.Zero;
while (monikerEnumerator.Next(1, monikers, numFetched) == 0)
{
IBindCtx ctx;
CreateBindCtx(0, out ctx);
string runningObjectName;
monikers[0].GetDisplayName(ctx, null, out runningObjectName);
if (re.IsMatch(runningObjectName))
{
object runningObjectVal;
runningObjectTable.GetObject(monikers[0], out runningObjectVal);
EnvDTE.Solution sln = runningObjectVal as EnvDTE.Solution;
if (sln != null)
return sln;
}
}
return null;
}
示例5: GetRunningObjectTable
/// <summary>
/// Retrieve the running object table
/// </summary>
/// <returns>A hashtable containing the running objects</returns>
private static Hashtable GetRunningObjectTable()
{
Hashtable result;
IntPtr numFetched;
IRunningObjectTable runningObjectTable;
IEnumMoniker monikerEnumerator;
IMoniker[] monikers;
IBindCtx ctx;
result = new Hashtable();
numFetched = new IntPtr();
monikers = new IMoniker[1];
GetRunningObjectTable(0, out runningObjectTable);
runningObjectTable.EnumRunning(out monikerEnumerator);
monikerEnumerator.Reset();
CreateBindCtx(0, out ctx);
while (monikerEnumerator.Next(1, monikers, numFetched) == 0)
{
string displayName;
object comObject;
monikers[0].GetDisplayName(ctx, null, out displayName);
runningObjectTable.GetObject(monikers[0], out comObject);
result[displayName] = comObject;
}
return result;
}
示例6: GetVSInstances
public static IEnumerable<KeyValuePair<Process, EnvDTE._DTE>> GetVSInstances()
{
IRunningObjectTable runningObjectTable = WinApiHelper.GetRunningObjectTable();
IEnumMoniker enumMoniker;
runningObjectTable.EnumRunning(out enumMoniker);
IMoniker[] monikers = new IMoniker[1];
for(enumMoniker.Reset(); enumMoniker.Next(1, monikers, IntPtr.Zero) == 0; ) {
EnvDTE._DTE dte;
Process dteProcess;
try {
IBindCtx ctx = WinApiHelper.NewBindCtx();
string runningObjectName;
monikers[0].GetDisplayName(ctx, null, out runningObjectName);
if(!runningObjectName.StartsWith("!VisualStudio") && !runningObjectName.StartsWith("!WDExpress.DTE")) continue;
object runningObjectVal;
runningObjectTable.GetObject(monikers[0], out runningObjectVal);
dte = runningObjectVal as EnvDTE._DTE;
if(dte == null) continue;
int dteProcessId = int.Parse(runningObjectName.Split(':')[1]);
dteProcess = Process.GetProcessById(dteProcessId);
} catch {
continue;
}
yield return new KeyValuePair<Process, EnvDTE._DTE>(dteProcess, dte);
}
}
示例7: GetActiveObjectList
/// <summary>
/// Get a snapshot of the running object table (ROT).
/// </summary>
/// <param name="filter">The filter to apply to the list (nullable).</param>
/// <returns>A hashtable of the matching entries in the ROT</returns>
public static Hashtable GetActiveObjectList(string filter)
{
var result = new Hashtable();
IntPtr numFetched = IntPtr.Zero;
IRunningObjectTable runningObjectTable;
IEnumMoniker monikerEnumerator;
var monikers = new IMoniker[1];
NativeMethods.GetRunningObjectTable(0, out runningObjectTable);
runningObjectTable.EnumRunning(out monikerEnumerator);
monikerEnumerator.Reset();
while (monikerEnumerator.Next(1, monikers, numFetched) == 0)
{
IBindCtx ctx;
NativeMethods.CreateBindCtx(0, out ctx);
string runningObjectName;
monikers[0].GetDisplayName(ctx, null, out runningObjectName);
object runningObjectVal;
runningObjectTable.GetObject(monikers[0], out runningObjectVal);
if (string.IsNullOrEmpty(filter) || runningObjectName.IndexOf(filter, StringComparison.OrdinalIgnoreCase) != -1)
{
result[runningObjectName] = runningObjectVal;
}
}
return result;
}
示例8: GetCurrent
internal static DTE2 GetCurrent()
{
//rot entry for visual studio running under current process.
string rotEntry = String.Format("!VisualStudio.DTE.10.0:{0}", Process.GetCurrentProcess().Id);
IRunningObjectTable rot;
GetRunningObjectTable(0, out rot);
IEnumMoniker enumMoniker;
rot.EnumRunning(out enumMoniker);
enumMoniker.Reset();
IntPtr fetched = IntPtr.Zero;
IMoniker[] moniker = new IMoniker[1];
while (enumMoniker.Next(1, moniker, fetched) == 0)
{
IBindCtx bindCtx;
CreateBindCtx(0, out bindCtx);
string displayName;
moniker[0].GetDisplayName(bindCtx, null, out displayName);
if (displayName == rotEntry)
{
object comObject;
rot.GetObject(moniker[0], out comObject);
return (EnvDTE80.DTE2)comObject;
}
}
return null;
}
示例9: GetByID
public static DTE2 GetByID(int ID)
{
//rot entry for visual studio running under current process.
string rotEntry = String.Format("!VisualStudio.DTE.10.0:{0}", ID);
IRunningObjectTable rot;
GetRunningObjectTable(0, out rot);
IEnumMoniker enumMoniker;
rot.EnumRunning(out enumMoniker);
enumMoniker.Reset();
IntPtr fetched = IntPtr.Zero;
IMoniker[] moniker = new IMoniker[1];
while (enumMoniker.Next(1, moniker, fetched) == 0)
{
IBindCtx bindCtx;
CreateBindCtx(0, out bindCtx);
string displayName;
moniker[0].GetDisplayName(bindCtx, null, out displayName);
if (displayName.StartsWith("!VisualStudio.DTE.", StringComparison.OrdinalIgnoreCase) &&
displayName.EndsWith(ID.ToString()))
{
object comObject;
rot.GetObject(moniker[0], out comObject);
return (EnvDTE80.DTE2)comObject;
}
}
return null;
}
示例10: GetCurrent
public static DTE2 GetCurrent()
{
// root entry for visual studio running under current process.
var rootEntry = $"!VisualStudio.DTE.12.0:{Process.GetCurrentProcess().Id}";
IRunningObjectTable rot;
NativeMethods.GetRunningObjectTable(0, out rot);
IEnumMoniker enumMoniker;
rot.EnumRunning(out enumMoniker);
enumMoniker.Reset();
var fetched = IntPtr.Zero;
var moniker = new IMoniker[1];
while (enumMoniker.Next(1, moniker, fetched) == 0)
{
IBindCtx bindCtx;
NativeMethods.CreateBindCtx(0, out bindCtx);
string displayName;
moniker[0].GetDisplayName(bindCtx, null, out displayName);
if (displayName == rootEntry)
{
object comObject;
rot.GetObject(moniker[0], out comObject);
return (DTE2)comObject;
}
}
return null;
}
示例11: Download
/// <summary>
/// Return S_OK (0) so that IE will stop to download the file itself.
/// Else the default download user interface is used.
/// </summary>
public int Download(IMoniker pmk, IBindCtx pbc, uint dwBindVerb, int grfBINDF,
IntPtr pBindInfo, string pszHeaders, string pszRedir, uint uiCP)
{
// Get the display name of the pointer to an IMoniker interface that specifies
// the object to be downloaded.
string name = string.Empty;
pmk.GetDisplayName(pbc, null, out name);
if (!string.IsNullOrEmpty(name))
{
Uri url = null;
bool result = Uri.TryCreate(name, UriKind.Absolute, out url);
if (result)
{
MessageBox.Show(url.ToString());
//pmk.BindToStorage(pbc,null,);
//// Launch CSWebDownloader.exe to download the file.
//FileInfo assemblyFile =
// new FileInfo(Assembly.GetExecutingAssembly().Location);
//ProcessStartInfo start = new ProcessStartInfo
//{
// Arguments = name,
// FileName =
// string.Format("{0}\\CSWebDownloader.exe", assemblyFile.DirectoryName)
//};
//Process.Start(start);
return 0;
}
}
return 1;
}
示例12: GetDevicesOfCat
public static bool GetDevicesOfCat(Guid cat, out ArrayList devs)
{
devs = null;
int hr;
object comObj = null;
ICreateDevEnum enumDev = null;
IEnumMoniker enumMon = null;
IMoniker[] mon = new IMoniker[1];
try
{
Type srvType = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum);
if (srvType == null)
throw new NotImplementedException("System Device Enumerator");
comObj = Activator.CreateInstance(srvType);
enumDev = (ICreateDevEnum)comObj;
hr = enumDev.CreateClassEnumerator(ref cat, out enumMon, 0);
if (hr != 0)
throw new NotSupportedException("No devices of the category");
int count = 0;
IntPtr f = IntPtr.Zero;
do
{
hr = enumMon.Next(1, mon, f);
if ((hr != 0) || (mon[0] == null))
break;
DsDevice dev = new DsDevice();
dev.Name = GetFriendlyName(mon[0]);
if (devs == null)
devs = new ArrayList();
dev.Mon = mon[0]; mon[0] = null;
devs.Add(dev); dev = null;
count++;
}
while (true);
return count > 0;
}
catch (Exception)
{
if (devs != null)
{
foreach (DsDevice d in devs)
d.Dispose();
devs = null;
}
return false;
}
finally
{
enumDev = null;
if (mon[0] != null)
Marshal.ReleaseComObject(mon[0]); mon[0] = null;
if (enumMon != null)
Marshal.ReleaseComObject(enumMon); enumMon = null;
if (comObj != null)
Marshal.ReleaseComObject(comObj); comObj = null;
}
}
示例13: GetDTE
public static DTE GetDTE(string processID)
{
IRunningObjectTable prot;
IEnumMoniker pMonkEnum;
string progID = "!VisualStudio.DTE.8.0:" + processID;
GetRunningObjectTable(0, out prot);
prot.EnumRunning(out pMonkEnum);
pMonkEnum.Reset();
IntPtr fetched = IntPtr.Zero;
IMoniker[] pmon = new IMoniker[1];
while (pMonkEnum.Next(1, pmon, fetched) == 0)
{
IBindCtx pCtx;
CreateBindCtx(0, out pCtx);
string str;
pmon[0].GetDisplayName(pCtx, null, out str);
if (str == progID)
{
object objReturnObject;
prot.GetObject(pmon[0], out objReturnObject);
DTE ide = (DTE)objReturnObject;
return ide;
}
}
return null;
}
示例14: GetE3Applications
public static IEnumerable<KeyValuePair<int, object>> GetE3Applications()
{
IRunningObjectTable runningObjectTable;
IEnumMoniker monikerEnumerator;
var monikers = new IMoniker[1];
IBindCtx ctx;
WinApi.CreateBindCtx(0, out ctx);
ctx.GetRunningObjectTable(out runningObjectTable);
runningObjectTable.EnumRunning(out monikerEnumerator);
monikerEnumerator.Reset();
while (monikerEnumerator.Next(1, monikers, IntPtr.Zero) == 0)
{
string runningObjectName;
monikers[0].GetDisplayName(ctx, null, out runningObjectName);
if (!runningObjectName.StartsWith("!E3Application", StringComparison.InvariantCultureIgnoreCase))
continue;
int index = runningObjectName.IndexOf(':');
if (index == -1) continue;
object runningObjectVal;
runningObjectTable.GetObject(monikers[0], out runningObjectVal);
yield return
new KeyValuePair<int, object>(int.Parse(runningObjectName.Substring(index + 1)),
runningObjectVal);
}
}
示例15: GetInstances
public static IEnumerable<DTE> GetInstances()
{
IRunningObjectTable rot;
IEnumMoniker enumMoniker;
int retVal = GetRunningObjectTable(0, out rot);
if (retVal == 0)
{
rot.EnumRunning(out enumMoniker);
IntPtr fetched = IntPtr.Zero;
IMoniker[] moniker = new IMoniker[1];
while (enumMoniker.Next(1, moniker, fetched) == 0)
{
IBindCtx bindCtx;
CreateBindCtx(0, out bindCtx);
string displayName;
moniker[0].GetDisplayName(bindCtx, null, out displayName);
Console.WriteLine("Display Name: {0}", displayName);
bool isVisualStudio = displayName.StartsWith("!VisualStudio");
if (isVisualStudio)
{
object dte = null;
//var dte = rot.GetObject(moniker) as DTE;
var x = rot.GetObject(moniker[0], out dte);
yield return dte as DTE;
}
}
}
}