Click here to Skip to main content
13,050,450 members (100,377 online)
Rate this:
Please Sign up or sign in to vote.

I am working on an Add in To Excel performing some operations on OLE object. It requires getting some data from OLE object embedded programmatically in worksheet (conversion from math type to TeX language). So far I've dealt with most of the issues like adding it to excel worksheet, getting the equation from Math Type OLE object and setting the equation. But there's the last thing to do.

I need to extract the metafile with image of the equation set by math type OLE object. I want to extract the image and save it as a memory bitmap and then display it in some kind of control. The issue is - I have the code to get the Metafile from OLE object:

 MTSDKDN.MathTypeSDK.IOleObject oleObject = null;
            oleDataObject = dataObject as IDataObject;
            oleObject = dataObject as MTSDKDN.MathTypeSDK.IOleObject;
            ConnectFORMATETC formatEtc = new ConnectFORMATETC();
            ConnectSTGMEDIUM stgMedium = new ConnectSTGMEDIUM();
            DataFormats.Format dataFormat;
                dataObject = obj.Object;
             formatEtc.cfFormat =(Int16)DataFormats.GetFormat(DataFormats.MetafilePict ).Id;
            formatEtc.dwAspect =  System.Runtime.InteropServices.ComTypes.DVASPECT.DVASPECT_CONTENT;
            formatEtc.lindex = -1;
            formatEtc.ptd = (IntPtr)0;
            formatEtc.tymed = TYMED.TYMED_MFPICT;
            oleDataObject.GetData(ref formatEtc,out stgMedium);
//get data returns proper data
//what to do now?
            IntPtr ptr;
            ptr = stgMedium.unionmember;
            HandleRef handleRef = new HandleRef(null, ptr);
            IntPtr ptrToHandle = GlobalLock(handleRef);
            int Length = GlobalSize(handleRef);

I have no idea if I'm doing the right thing to get the metafile, and the most imprtant (assuming that ist ok getting the metafile this way): how to manage the metafile to save the image data as bitmap in add-in's memory.

I would be really garteful for your answer.
Posted 9-Sep-12 3:41am
Updated 9-Sep-12 3:47am
tomekchacuk 10-Sep-12 15:31pm
Anyone ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 9 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100