Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hello,
 
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;
 
obj.Verb((Excel.XlOLEVerb)3);
                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;
 
            stgMedium.unionmember=(IntPtr)0;
            stgMedium.tymed=TYMED.TYMED_NULL;
            stgMedium.pUnkForRelease=0;
 
            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 4:41am
Edited 9-Sep-12 4:47am
v2
Comments
tomekchacuk at 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
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 BillWoodruff 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 9 Sep 2012
Copyright © CodeProject, 1999-2014
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