示例#1
0
        public int RegisterObject(object obj, string stringId)
        {
            int regId = -1;

            System.Runtime.InteropServices.ComTypes.IRunningObjectTable pROT     = null;
            System.Runtime.InteropServices.ComTypes.IMoniker            pMoniker = null;

            int hr;

            if ((hr = NativeMethods.GetRunningObjectTable((uint)0, out pROT)) != 0)
            {
                return(hr);
            }

            // File Moniker has to be used because in VBS GetObject only works with file monikers in the ROT
            if ((hr = NativeMethods.CreateFileMoniker(stringId, out pMoniker)) != 0)
            {
                return(hr);
            }


            regId = pROT.Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, obj, pMoniker);

            _RegisteredObjects.Add(new ObjectInRot(obj, regId));

            return(0);
        }
示例#2
0
        /// <summary>
        /// This allows us to register an object in the Running Object Table
        /// </summary>
        /// <param name="obj">A Com interface pointer owned by the object</param>
        /// <param name="stringId">A display name for the object</param>
        /// <returns>Returns two integers as an array, the first is the HRESULT of system calls and if successful the second is the registration id (regid).  You'll need the regid to revoke from the ROT when tidying up.</returns>
        public int[] RegisterObject(object obj, string stringId)
        {
            int[] retval = new int[] { 0, 0 };
            int   regId  = -1;

            System.Runtime.InteropServices.ComTypes.IRunningObjectTable pROT     = null;
            System.Runtime.InteropServices.ComTypes.IMoniker            pMoniker = null;
            int hr;

            if ((hr = RotNativeMethods.GetRunningObjectTable((int)0, out pROT)) != 0)
            {
                retval[0] = hr;
                return(retval);    //(hr);
            }
            // File Moniker has to be used because in VBS GetObject only works with file monikers in the ROT
            if ((hr = RotNativeMethods.CreateFileMoniker(stringId, out pMoniker)) != 0)
            {
                retval[0] = hr;
                return(retval);    //(hr);
            }
            int ROTFLAGS_REGISTRATIONKEEPSALIVE = 1;

            regId     = pROT.Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, obj, pMoniker);
            retval[0] = 0;
            retval[1] = regId;
            return(retval);
        }
示例#3
0
 private static Hashtable GetRunningObjectTable()
 {
     try
     {
         Hashtable result     = new Hashtable();
         IntPtr    numFetched = new IntPtr();
         System.Runtime.InteropServices.ComTypes.IRunningObjectTable runningObjectTable;
         System.Runtime.InteropServices.ComTypes.IEnumMoniker        monikerEnumerator;
         System.Runtime.InteropServices.ComTypes.IMoniker[]          monikers = new System.Runtime.InteropServices.ComTypes.IMoniker[1];
         GetRunningObjectTable(0, out runningObjectTable);
         runningObjectTable.EnumRunning(out monikerEnumerator);
         monikerEnumerator.Reset();
         while (monikerEnumerator.Next(1, monikers, numFetched) == 0)
         {
             System.Runtime.InteropServices.ComTypes.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);
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#4
0
 void IBclAdviseSink.OnRename(BclComTypes.IMoniker moniker)
 {
     if (null != bclSink)
     {
         bclSink.OnRename(moniker);
     }
     else
     {
         // TODO: Use the IMoniker converter when ready.
         oleSink.OnRename(null);
     }
 }
示例#5
0
 public static extern int CreatePointerMoniker([MarshalAs(UnmanagedType.IUnknown)] object
                                               punk, out System.Runtime.InteropServices.ComTypes.IMoniker ppmk);
示例#6
0
 public static extern int CreateFileMoniker([MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, out System.Runtime.InteropServices.ComTypes.IMoniker ppmk);
示例#7
0
 int IOleClientSite.GetMoniker(uint dwAssign, uint dwWhichMoniker, out System.Runtime.InteropServices.ComTypes.IMoniker ppmk)
 {
     ppmk = null;
     return(Hresults.E_NOTIMPL);
 }
 private static extern Int32 CreateItemMoniker(string delim, string item, out comTypes.IMoniker moniker);
 private void textBoxTelemetryDestination_TextChanged(object sender, EventArgs e)
 {
     this.pmkTelemetryDestination = null;
 }
        private void textBoxTelemetryDestination_DragDrop(object sender, DragEventArgs e)
        {
            if (this.CanAcceptDrop(e))
                {
                // Dig out and reify the serialized moniker which is living in the Link Source
                //
                COMTypes.IMoniker pmkTelemetryDestination = MonikerFromData(e.Data);
                if (null != pmkTelemetryDestination)
                    {
                    // Find out the moniker's display name
                    //
                    COMTypes.IBindCtx pbc = WIN32.CreateBindContext();
                    string displayName;
                    pmkTelemetryDestination.GetDisplayName(pbc, null, out displayName);
                    //
                    // Put it on the screen and remember it
                    //
                    this.textBoxTelemetryDestination.Text = displayName;
                    this.pmkTelemetryDestination = pmkTelemetryDestination;
                    }

                // Report 'no dice' so the source leaves what we were dragging alone:
                // we were only really interested in the moniker. But if we can tell
                // them we *did* make a link, then we do so, so he might better maintain
                // it for us (good moniker hygene, but not really important in Excel).
                if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link)
                    e.Effect = DragDropEffects.Link;
                else
                    e.Effect = DragDropEffects.None;
                }
        }
        void OpenTelemetryDestination()
        {
            if (null == this.pmkTelemetryDestination && this.textBoxTelemetryDestination.Text.Length > 0)
                {
                this.pmkTelemetryDestination = WIN32.MkParseDisplayName(this.textBoxTelemetryDestination.Text);
                }
            //
            if (null != this.pmkTelemetryDestination)
                {
                // Bind the moniker!
                //
                COMTypes.IBindCtx pbc = WIN32.CreateBindContext();
                object punk;
                this.pmkTelemetryDestination.BindToObject(pbc, null, ref WIN32.IID_IUnknown, out punk);
                //
                // Is this Excel?
                //
                Excel.Workbook workbook = punk as Excel.Workbook;
                if (null != workbook)
                    {
                    // Make the target visible and selected
                    WIN32.IOleClientSite clientSite = new WIN32.OleClientSite();
                    ((WIN32.IOleObject)punk).DoVerb(WIN32.OLEIVERB.SHOW, IntPtr.Zero, clientSite, 0, IntPtr.Zero, IntPtr.Zero);

                    // Interogate the selection to get the range to use (we note just the upper left hand corner)
                    dynamic sel = ((Excel.Workbook)punk).Application.Selection;
                    Excel.Range range = (Excel.Range)sel;               // REVIEW: might throw if not just one range?

                    // Remember the Sheet
                    Program.TelemetryContext.Sheet = range.Worksheet;

                    // Remember the location on the Sheet. But if the whole Sheet is selected,
                    // change the selection just as we do for a new blank Sheet. We hit this case
                    // when the moniker we bound is the whole file, e.g., c:\tmp\book2.xlsx
                    long cCellFullSheet = (long)16384 * 1048576;
                    long cCellSelected  = range.CountLarge;
                    if (cCellSelected >= cCellFullSheet)
                        {
                        Program.TelemetryContext.InitCursor(0,0);
                        Program.TelemetryContext.Sheet.get_Range(TelemetryRecord.CellName(0,0)).Select();
                        }
                    else
                        {
                        Program.TelemetryContext.InitCursor(-1, -1);
                        }
                    }
                else
                    {
                    throw new InvalidComObjectException("telemetry destination not an Excel sheet");
                    }
                }
            else
                {
                // Open a new Excel workbook
                //
                Excel.Application app = GetExcelApp();
                app.Workbooks.Add();
                Program.TelemetryContext.Sheet = (Excel.Worksheet)(app.Worksheets[1]);
                Program.TelemetryContext.InitCursor(0,0);
                }

            if (null != Program.TelemetryContext.Sheet)
                {
                Program.TelemetryContext.Workbook = (Excel.Workbook)(Program.TelemetryContext.Sheet.Parent);
                }
        }
示例#12
0
 internal static extern int CreateItemMoniker([MarshalAs(UnmanagedType.LPWStr)] string
                                              lpszDelim, [MarshalAs(UnmanagedType.LPWStr)] string lpszItem,
                                              out System.Runtime.InteropServices.ComTypes.IMoniker ppmk);
示例#13
0
        /// <summary>
        /// フィルタ一覧の取得
        /// </summary>
        /// <param name="category">デバイスのカテゴリ</param>
        /// <returns>
        ///		取得したフィルタ情報のコレクションを返します。
        /// </returns>
        public static List <CxFilterInfo> GetFilterList(Guid category)
        {
            var result = new List <CxFilterInfo>();

            System.Runtime.InteropServices.ComTypes.IEnumMoniker enumerator = null;
            ICreateDevEnum device = null;

            try
            {
                // ICreateDevEnum インターフェース取得.
                device = (ICreateDevEnum)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_SystemDeviceEnum)));

                // EnumMonikerの作成.
                device.CreateClassEnumerator(ref category, ref enumerator, 0);
                if (enumerator == null)
                {
                    return(result);
                }

                // 列挙.
                var monikers = new System.Runtime.InteropServices.ComTypes.IMoniker[1];
                var fetched  = IntPtr.Zero;

                while (enumerator.Next(monikers.Length, monikers, fetched) == 0)
                {
                    // プロパティバッグへのバインド.
                    IPropertyBag propbag = null;
                    {
                        object tmp  = null;
                        Guid   guid = new Guid(GUID.IID_IPropertyBag);
                        monikers[0].BindToStorage(null, null, ref guid, out tmp);
                        propbag = (IPropertyBag)tmp;
                    }

                    try
                    {
                        var info = new CxFilterInfo();

                        // 名前取得.
                        try
                        {
                            object friendly_name = null;
                            propbag.Read("FriendlyName", ref friendly_name, 0);
                            info.Name = (string)friendly_name;
                        }
                        catch (Exception)
                        {
                        }

                        // CLSID取得.
                        try
                        {
                            object clsid = null;
                            propbag.Read("CLSID", ref clsid, 0);
                            info.CLSID = (string)clsid;
                        }
                        catch (Exception)
                        {
                        }

                        // コレクションに追加.
                        result.Add(info);
                    }
                    finally
                    {
                        // プロパティバッグの解放.
                        Marshal.ReleaseComObject(propbag);

                        // 列挙したモニカの解放.
                        for (int mmm = 0; mmm < monikers.Length; mmm++)
                        {
                            if (monikers[mmm] != null)
                            {
                                Marshal.ReleaseComObject(monikers[mmm]);
                            }
                            monikers[mmm] = null;
                        }
                    }
                }

                // 同名フィルタの順番付け.
                for (int i = 0; i < result.Count - 1; i++)
                {
                    for (int j = i + 1; j < result.Count; j++)
                    {
                        if (result[j].Name == result[i].Name)
                        {
                            result[j].Index = result[i].Index + 1;
                            break;
                        }
                    }
                }
            }
            finally
            {
                if (enumerator != null)
                {
                    Marshal.ReleaseComObject(enumerator);
                }
                if (device != null)
                {
                    Marshal.ReleaseComObject(device);
                }
            }

            return(result);
        }
示例#14
0
        /// <summary>
        /// フィルタ生成
        /// </summary>
        /// <param name="category">フィルタのカテゴリ</param>
        /// <param name="clsid">フィルタの CLSID (省略する場合は null を指定してください。)</param>
        /// <param name="index">指標 [0~]</param>
        /// <returns>
        ///		生成されたフィルタを返します。
        /// </returns>
        /// <remarks>
        ///		seealso: https://msdn.microsoft.com/en-us/library/windows/desktop/dd407292(v=vs.85).aspx <br/>
        /// </remarks>
        public static IBaseFilter CreateFilter(Guid category, string clsid, int index)
        {
            System.Runtime.InteropServices.ComTypes.IEnumMoniker enumerator = null;
            ICreateDevEnum device = null;

            try
            {
                // ICreateDevEnum インターフェース取得.
                device = (ICreateDevEnum)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_SystemDeviceEnum)));

                // EnumMonikerの作成.
                device.CreateClassEnumerator(ref category, ref enumerator, 0);

                // 列挙.
                var    monikers = new System.Runtime.InteropServices.ComTypes.IMoniker[1];
                IntPtr fetched  = IntPtr.Zero;

                while (enumerator.Next(monikers.Length, monikers, fetched) == 0)
                {
                    System.Runtime.InteropServices.ComTypes.IMoniker moniker = monikers[0];

                    // プロパティバッグへのバインド.
                    IPropertyBag propbag = null;
                    {
                        object tmp  = null;
                        Guid   guid = new Guid(GUID.IID_IPropertyBag);
                        moniker.BindToStorage(null, null, ref guid, out tmp);
                        propbag = (IPropertyBag)tmp;
                    }

                    try
                    {
                        // フィルタ名の判定.
                        if (!string.IsNullOrEmpty(clsid))
                        {
                            object tmp = null;
                            propbag.Read("CLSID", ref tmp, 0);
                            if ((string)tmp != clsid)
                            {
                                continue;
                            }
                        }

                        // 指標の判定.
                        if (index > 0)
                        {
                            index--;
                            continue;
                        }

                        // フィルタインスタンス取得.
                        object filter = null;
                        {
                            Guid guid = new Guid(GUID.IID_IBaseFilter);
                            moniker.BindToObject(null, null, ref guid, out filter);
                        }
                        if (filter == null)
                        {
                            throw new System.NotSupportedException();
                        }
                        return((IBaseFilter)filter);
                    }
                    finally
                    {
                        // プロパティバッグの解放
                        Marshal.ReleaseComObject(propbag);

                        // 列挙したモニカの解放.
                        for (int mmm = 0; mmm < monikers.Length; mmm++)
                        {
                            if (monikers[mmm] != null)
                            {
                                Marshal.ReleaseComObject(monikers[mmm]);
                            }
                            monikers[mmm] = null;
                        }
                    }
                }
                throw new System.NotSupportedException();
            }
            finally
            {
                if (enumerator != null)
                {
                    Marshal.ReleaseComObject(enumerator);
                }
                if (device != null)
                {
                    Marshal.ReleaseComObject(device);
                }
            }
        }