public MTAPISmokeTest() { _appHelper = new AppHelper(); //_MTSDK = new MathTypeSDK(); _MTSDK = MathTypeSDK.Instance; _isMTAPIConnected = false; InitializeComponent(); }
override public bool GetMTEF() { bool bReturn = false; if (!sdk.Init()) { return(bReturn); } IDataObject dataObject = MathTypeSDK.getIDataObject(); if (dataObject == null) { sdk.DeInit(); return(bReturn); } FORMATETC formatEtc = new FORMATETC(); STGMEDIUM stgMedium = new STGMEDIUM(); try { // Setup the formatting information to use for the conversion. formatEtc.cfFormat = (Int16)DataFormats.GetFormat(strInTrans).Id; formatEtc.dwAspect = DVASPECT.DVASPECT_CONTENT; formatEtc.lindex = -1; formatEtc.ptd = (IntPtr)0; formatEtc.tymed = TYMED.TYMED_HGLOBAL; // Setup the MathML content to convert stgMedium.unionmember = Marshal.StringToHGlobalAuto(strEquation); stgMedium.tymed = TYMED.TYMED_HGLOBAL; stgMedium.pUnkForRelease = 0; // Perform the conversion dataObject.SetData(ref formatEtc, ref stgMedium, false); // Set the format for the output formatEtc.cfFormat = (Int16)DataFormats.GetFormat("MathType EF").Id; formatEtc.dwAspect = DVASPECT.DVASPECT_CONTENT; formatEtc.lindex = -1; formatEtc.ptd = (IntPtr)0; formatEtc.tymed = TYMED.TYMED_ISTORAGE; // Create a blank data structure to hold the converted result. stgMedium = new STGMEDIUM(); stgMedium.tymed = TYMED.TYMED_NULL; stgMedium.pUnkForRelease = 0; // Get the conversion result in MTEF format dataObject.GetData(ref formatEtc, out stgMedium); } catch (COMException e) { Console.WriteLine("MathML conversion to MathType threw an exception: " + Environment.NewLine + e.ToString()); sdk.DeInit(); return(bReturn); } // The pointer now becomes a Handle reference. HandleRef handleRef = new HandleRef(null, stgMedium.unionmember); try { // Lock in the handle to get the pointer to the data IntPtr ptrToHandle = MathTypeSDK.GlobalLock(handleRef); // Get the size of the memory block m_iMTEF_Length = MathTypeSDK.GlobalSize(handleRef); // New an array of bytes and Marshal the data across. m_bMTEF = new byte[m_iMTEF_Length]; Marshal.Copy(ptrToHandle, m_bMTEF, 0, m_iMTEF_Length); m_strMTEF = System.Text.ASCIIEncoding.ASCII.GetString(m_bMTEF); bReturn = true; } catch (Exception e) { Console.WriteLine("Generation of image from MathType failed: " + Environment.NewLine + e.ToString()); } finally { MathTypeSDK.GlobalUnlock(handleRef); } sdk.DeInit(); return(bReturn); }