public COMCallableIUnknown() { _handle = GCHandle.Alloc(this); IUnknownVTable * vtable = (IUnknownVTable *)Marshal.AllocHGlobal(sizeof(IUnknownVTable)).ToPointer(); QueryInterfaceDelegate qi = new QueryInterfaceDelegate(QueryInterfaceImpl); vtable->QueryInterface = Marshal.GetFunctionPointerForDelegate(qi); _delegates.Add(qi); AddRefDelegate addRef = new AddRefDelegate(AddRefImpl); vtable->AddRef = Marshal.GetFunctionPointerForDelegate(addRef); _delegates.Add(addRef); ReleaseDelegate release = new ReleaseDelegate(ReleaseImpl); vtable->Release = Marshal.GetFunctionPointerForDelegate(release); _delegates.Add(release); IUnknownObject = Marshal.AllocHGlobal(IntPtr.Size); *(void **)IUnknownObject = vtable; _interfaces.Add(IUnknownGuid, IUnknownObject); }
public int AddRef() { if (_addRef == null) { _addRef = (AddRefDelegate)Marshal.GetDelegateForFunctionPointer(_unknownVTable->AddRef, typeof(AddRefDelegate)); } int count = _addRef(Self); return(count); }
public static IntPtr Create( QueryInterfaceDelegate queryInterface, AddRefDelegate addRef, ReleaseDelegate release, BarDelegate bar) { var instance = new ManualVTable { QueryInterface = Marshal.GetFunctionPointerForDelegate(queryInterface), AddRef = Marshal.GetFunctionPointerForDelegate(addRef), Release = Marshal.GetFunctionPointerForDelegate(release), Bar = Marshal.GetFunctionPointerForDelegate(bar) }; var marshalledInstance = Marshal.AllocHGlobal(Marshal.SizeOf(instance)); Marshal.StructureToPtr(instance, marshalledInstance, false); return(marshalledInstance); }
static Win32DnD() { // Required for all other OLE functions to work Win32OleInitialize(IntPtr.Zero); // We reuse those DragDropEventArgs = new DragEventArgs(new DataObject(DataFormats.FileDrop, new string[0]), 0, 0, 0, DragDropEffects.None, DragDropEffects.None); DragFeedbackEventArgs = new GiveFeedbackEventArgs(DragDropEffects.None, true); DragContinueEventArgs = new QueryContinueDragEventArgs(0, false, DragAction.Continue); DragFormats = new ArrayList(); DragFormatArray = new FORMATETC[0]; DragMediums = new ArrayList(); // Set up delegates // IDataObject DOQueryInterface = new QueryInterfaceDelegate(ComIDataObject.QueryInterface); DOAddRef = new AddRefDelegate(ComIDataObject.AddRef); DORelease = new ReleaseDelegate(ComIDataObject.Release); GetData = new GetDataDelegate(ComIDataObject.GetData); GetDataHere = new GetDataHereDelegate(ComIDataObject.GetDataHere); QueryGetData = new QueryGetDataDelegate(ComIDataObject.QueryGetData); GetCanonicalFormatEtc = new GetCanonicalFormatEtcDelegate(ComIDataObject.GetCanonicalFormatEtc); SetData = new SetDataDelegate(ComIDataObject.SetData); EnumFormatEtc = new EnumFormatEtcDelegate(ComIDataObject.EnumFormatEtc); DAdvise = new DAdviseDelegate(ComIDataObject.DAdvise); DUnadvise = new DUnadviseDelegate(ComIDataObject.DUnadvise); EnumDAdvise = new EnumDAdviseDelegate(ComIDataObject.EnumDAdvise); // IDropSource DSQueryInterface = new QueryInterfaceDelegate(ComIDropSource.QueryInterface); DSAddRef = new AddRefDelegate(ComIDropSource.AddRef); DSRelease = new ReleaseDelegate(ComIDropSource.Release); QueryContinueDrag = new QueryContinueDragDelegate(ComIDropSource.QueryContinueDrag); GiveFeedback = new GiveFeedbackDelegate(ComIDropSource.GiveFeedback); // IDropTarget DTQueryInterface = new QueryInterfaceDelegate(ComIDropTarget.QueryInterface); DTAddRef = new AddRefDelegate(ComIDropTarget.AddRef); DTRelease = new ReleaseDelegate(ComIDropTarget.Release); DragEnter = new DragEnterDelegate(ComIDropTarget.DragEnter); DragOver = new DragOverDelegate(ComIDropTarget.DragOver); DragLeave = new DragLeaveDelegate(ComIDropTarget.DragLeave); Drop = new DropDelegate(ComIDropTarget.Drop); }
private void SetupIUnknownMethods() { /* Read the COM v-table pointer */ IntPtr pVtable = Marshal.ReadIntPtr(m_comPointer); const int ADDREF_VTABLE_INDEX = 0; const int RELEASE_VTABLE_INDEX = 1; const int QUERYINTERFACE_VTABLE_INDEX = 2; /* Get the function pointer */ IntPtr pFunc = Marshal.ReadIntPtr(pVtable, ADDREF_VTABLE_INDEX * IntPtr.Size); /* Cast the function pointer to a .NET delegate */ AddRefMethod = (AddRefDelegate)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(AddRefDelegate)); /* Rinse and repeat */ pFunc = Marshal.ReadIntPtr(pVtable, RELEASE_VTABLE_INDEX * IntPtr.Size); ReleaseMethod = (ReleaseDelegate)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(ReleaseDelegate)); pFunc = Marshal.ReadIntPtr(pVtable, QUERYINTERFACE_VTABLE_INDEX * IntPtr.Size); QueryInterfaceMethod = (QueryInterfaceDelegate)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(QueryInterfaceDelegate)); }
public static IntPtr Create( QueryInterfaceDelegate queryInterface, AddRefDelegate addRef, ReleaseDelegate release, BarDelegate bar) { var instance = new ManualVTable { QueryInterface = Marshal.GetFunctionPointerForDelegate(queryInterface), AddRef = Marshal.GetFunctionPointerForDelegate(addRef), Release = Marshal.GetFunctionPointerForDelegate(release), Bar = Marshal.GetFunctionPointerForDelegate(bar) }; var marshalledInstance = Marshal.AllocHGlobal(Marshal.SizeOf(instance)); Marshal.StructureToPtr(instance, marshalledInstance, false); return marshalledInstance; }