Beispiel #1
0
        private void InitThreadSafeStuff(IDebugClient debugClient)
        {
            _myThread = Thread.CurrentThread;

            //
            // Save our DebugClientPtr address for later use (if it hasn't been done already)
            //
            if (_debugClientPtr == IntPtr.Zero ||
                _createClientDelegate == null)
            {
                IntPtr iUnknown = Marshal.GetIUnknownForObject(debugClient);

                Guid iDebugClientGuid = typeof(IDebugClient).GUID;

                int hr = Marshal.QueryInterface(iUnknown, ref iDebugClientGuid, out _debugClientPtr);
                if (hr != 0)
                {
                    throw new Exception();
                }
                try
                {
                    MemberInfo createClientMemberInfo = typeof(IDebugClient).GetMember("CreateClient", BindingFlags.Instance | BindingFlags.Public)[0];
                    int        createClientComSlot    = Marshal.GetComSlotForMethodInfo(createClientMemberInfo);
                    IntPtr     iDebugClientVtbl       = Marshal.ReadIntPtr(_debugClientPtr);
                    IntPtr     createClientPtr        = Marshal.ReadIntPtr(iDebugClientVtbl, IntPtr.Size * createClientComSlot);
                    _createClientDelegate = (CreateClientDelegate)Marshal.GetDelegateForFunctionPointer(createClientPtr, typeof(CreateClientDelegate));
                }
                finally
                {
                    // leaking this on purpose.  Trying to fix refcount bug.
                    //Marshal.Release(iUnknown);
                }
            }
        }
Beispiel #2
0
        private void BtClientClick(object sender, EventArgs e)
        {
            var form   = new Dialog.NodeActionForm("client");
            var result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                String[] args = new string[3];
                args[0] = form.item1;
                args[1] = form.item2;
                args[2] = form.item3;
                CreateClientDelegate del = new CreateClientDelegate(CreateClient);
                var workTask             = Task.Run(() => del.Invoke(args));
            }
        }