Ejemplo n.º 1
0
        private IntPtr GetObjectDescriptor(string name, string src)
        {
            var s1             = Encoding.Unicode.GetBytes(name);
            var s2             = Encoding.Unicode.GetBytes(src);
            var l1             = Marshal.SizeOf(typeof(OBJECTDESCRIPTOR));
            var l2             = l1 + s1.Length + 2;
            var len            = l2 + s2.Length + 2;
            var ret            = Marshal.AllocHGlobal(len);
            OBJECTDESCRIPTOR d = new OBJECTDESCRIPTOR
            {
                cbSize             = len,
                clsid              = GetGuid(),
                dwDrawAspect       = 1,
                sizel_x            = 300, //TODO
                sizel_y            = 200,
                dwFullUserTypeName = l1,
                dwSrcOfCopy        = l2,
            };

            Marshal.StructureToPtr(d, ret, false);
            Marshal.Copy(s1, 0, IntPtr.Add(ret, l1), s1.Length);
            Marshal.WriteInt16(ret, l2 - 2, 0);
            Marshal.Copy(s2, 0, IntPtr.Add(ret, l2), s2.Length);
            Marshal.WriteInt16(ret, len - 2, 0);
            return(ret);
        }
Ejemplo n.º 2
0
        public static IntPtr RenderLinkedObjectDescriptor(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.RenderLinkedObjectDescriptor");

            // Brockschmidt, Inside Ole 2nd ed. page 991
            if (!(tymed == TYMED.TYMED_HGLOBAL))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
            }
            // Fill in the basic information.
            var od = new OBJECTDESCRIPTOR
            {
                // According to the documentation this is used just to find an icon.
                clsid        = typeof(GraphDocumentLinkedComObject).GUID,
                dwDrawAspect = DVASPECT.DVASPECT_CONTENT,
                sizelcx      = 0, // zero in imitation of Word/Excel, but could be box.Extent.cx;
                sizelcy      = 0, // zero in imitation of Word/Excel, but could be box.Extent.cy;
                pointlx      = 0,
                pointly      = 0
            };

            od.dwStatus = MiscStatus((int)od.dwDrawAspect);

            // Descriptive strings to tack on after the struct.
            string name        = GraphDocumentLinkedComObject.USER_TYPE;
            int    name_size   = (name.Length + 1) * sizeof(char);
            string source      = "Altaxo";
            int    source_size = (source.Length + 1) * sizeof(char);
            int    od_size     = Marshal.SizeOf(typeof(OBJECTDESCRIPTOR));

            od.dwFullUserTypeName = od_size;
            od.dwSrcOfCopy        = od_size + name_size;
            int full_size = od_size + name_size + source_size;

            od.cbSize = full_size;

            // To avoid 'unsafe', we will arrange the strings in a byte array.
            byte[]   strings = new byte[full_size];
            Encoding unicode = Encoding.Unicode;

            Array.Copy(unicode.GetBytes(name), 0, strings, od.dwFullUserTypeName, name.Length * sizeof(char));
            Array.Copy(unicode.GetBytes(source), 0, strings, od.dwSrcOfCopy, source.Length * sizeof(char));

            // Combine the strings and the struct into a single block of mem.
            IntPtr hod = Kernel32Func.GlobalAlloc(GlobalAllocFlags.GHND, full_size);

            if (!(hod != IntPtr.Zero))
            {
                throw new InvalidOperationException("GlobalAlloc operation was not successful");
            }
            IntPtr buf = Kernel32Func.GlobalLock(hod);

            Marshal.Copy(strings, 0, buf, full_size);
            Marshal.StructureToPtr(od, buf, false);

            Kernel32Func.GlobalUnlock(hod);
            return(hod);
        }
Ejemplo n.º 3
0
		public static IntPtr RenderLinkedObjectDescriptor(TYMED tymed)
		{
			ComDebug.ReportInfo("GraphDocumentDataObject.RenderLinkedObjectDescriptor");

			// Brockschmidt, Inside Ole 2nd ed. page 991
			if (!(tymed == TYMED.TYMED_HGLOBAL))
				throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
			// Fill in the basic information.
			OBJECTDESCRIPTOR od = new OBJECTDESCRIPTOR();
			// According to the documentation this is used just to find an icon.
			od.clsid = typeof(GraphDocumentLinkedComObject).GUID;
			od.dwDrawAspect = DVASPECT.DVASPECT_CONTENT;
			od.sizelcx = 0; // zero in imitation of Word/Excel, but could be box.Extent.cx;
			od.sizelcy = 0; // zero in imitation of Word/Excel, but could be box.Extent.cy;
			od.pointlx = 0;
			od.pointly = 0;
			od.dwStatus = MiscStatus((int)od.dwDrawAspect);

			// Descriptive strings to tack on after the struct.
			string name = GraphDocumentLinkedComObject.USER_TYPE;
			int name_size = (name.Length + 1) * sizeof(char);
			string source = "Altaxo";
			int source_size = (source.Length + 1) * sizeof(char);
			int od_size = Marshal.SizeOf(typeof(OBJECTDESCRIPTOR));
			od.dwFullUserTypeName = od_size;
			od.dwSrcOfCopy = od_size + name_size;
			int full_size = od_size + name_size + source_size;
			od.cbSize = full_size;

			// To avoid 'unsafe', we will arrange the strings in a byte array.
			byte[] strings = new byte[full_size];
			Encoding unicode = Encoding.Unicode;
			Array.Copy(unicode.GetBytes(name), 0, strings, od.dwFullUserTypeName, name.Length * sizeof(char));
			Array.Copy(unicode.GetBytes(source), 0, strings, od.dwSrcOfCopy, source.Length * sizeof(char));

			// Combine the strings and the struct into a single block of mem.
			IntPtr hod = Kernel32Func.GlobalAlloc(GlobalAllocFlags.GHND, full_size);
			if (!(hod != IntPtr.Zero))
				throw new InvalidOperationException("GlobalAlloc operation was not successful");
			IntPtr buf = Kernel32Func.GlobalLock(hod);
			Marshal.Copy(strings, 0, buf, full_size);
			Marshal.StructureToPtr(od, buf, false);

			Kernel32Func.GlobalUnlock(hod);
			return hod;
		}