Exemplo n.º 1
0
            private ManagedToNativeWrapper(IStream managedInterface)
            {
                IStreamInterface newInterface;

                lock (managedVtable)
                {
                    // Vtable may have been disposed when shutting down
                    if (vtableRefCount == 0 && comVtable == IntPtr.Zero)
                    {
                        CreateVtable();
                    }
                    vtableRefCount++;
                }

                try
                {
                    this.managedInterface = managedInterface;
                    gcHandle = GCHandle.Alloc(this);

                    newInterface          = new IStreamInterface();
                    newInterface.lpVtbl   = comVtable;
                    newInterface.gcHandle = (IntPtr)gcHandle;
                    comInterface          = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IStreamInterface)));
                    Marshal.StructureToPtr(newInterface, comInterface, false);
                }
                catch
                {
                    this.Dispose();
                    throw;
                }
            }
Exemplo n.º 2
0
			private ManagedToNativeWrapper(IStream managedInterface)
			{
				IStreamInterface newInterface;

				lock (managedVtable)
				{
					// Vtable may have been disposed when shutting down
					if (vtableRefCount == 0 && comVtable == IntPtr.Zero)
						CreateVtable();
					vtableRefCount++;
				}

				try
				{
					this.managedInterface = managedInterface;
					gcHandle = GCHandle.Alloc(this);

					newInterface = new IStreamInterface();
					newInterface.lpVtbl = comVtable;
					newInterface.gcHandle = (IntPtr)gcHandle;
					comInterface = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IStreamInterface)));
					Marshal.StructureToPtr(newInterface, comInterface, false);
				}
				catch
				{
					this.Dispose();
					throw;
				}
			}