Example #1
0
 public static extern void ReleaseStgMedium(ref STGMEDIUM pmedium);
Example #2
0
        /// <summary>
        /// Get object's ADS Path
        /// For properetysheets in Active Directory the code can 
        /// find what is the caller node .
        /// sClass , sObjADsPath will fill in this scenario.
        /// </summary>
        private unsafe void GetADPath()
        {
            FORMATETC fmt = new FORMATETC();
            fmt.cfFormat= (CLIPFORMAT)APIWrapper.RegisterClipboardFormat("DsObjectNames");//CLIPFORMAT.HDROP;
            fmt.ptd		= IntPtr.Zero;
            fmt.dwAspect= DVASPECT.CONTENT;
            fmt.lindex	= -1;
            fmt.tymed	= TYMED.HGLOBAL;

            STGMEDIUM medium = new STGMEDIUM();
            dobj.GetData(ref fmt, ref medium); // returned HRESULT

            DSOBJECTNAMES ds=(DSOBJECTNAMES) Marshal.PtrToStructure(
                medium.hGlobal, typeof(DSOBJECTNAMES));

            if(ds.cItems<1)
            {
                System.Windows.Forms.MessageBox.Show("AD clipboard error!");
                return;
            }

            // aObjects[0]; also : can use Marshal.Copy to avoid pointers.
            IntPtr pClass = new IntPtr(ds.aObjects.offsetClass + (uint)medium.hGlobal);
            sClass = new string( (char*) pClass.ToPointer());

            IntPtr pObjADsPath = new IntPtr( ds.aObjects.offsetName + (uint)medium.hGlobal);
            sObjADsPath = new string((char*) pObjADsPath.ToPointer());

            APIWrapper.ReleaseStgMedium(ref medium);
        }