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:

<pre lang="cs">
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.