我想在一个MathType应用程序中运行一个C# .在表单中使用OLE来表示方程/图像。
这就是我从代码开始的方式。我得到了数学类型方程的CLSID对象。我创建一个新实例并运行一个谓词来启动Math。在我尝试设置或获取我拥有的IDataItem属性的数据之前,这是很好的。
代码:
string progID = "Equation.DSMT4";
comRetVal= CLSIDFromProgID(progID, out eqContainerGUID);
Type t = Type.GetTypeFromProgID(progID); //ok-> MT6 Equation
Object instance = Activator.CreateInstance(t);
IDataObject oleDataObject = instance as IDataObject;
MTSDKDN.MathTypeSDK.IOleObject oleObject = instance as IDataObject;
//run verb Run For Conversion - I'm not sure what this verb does
oleObject.DoVerb(2, (IntPtr)0, activeSite, 0, (IntPtr)this.Handle, new MathTypeSDK.COMRECT());
//up to here everything is find
//Now say I want to put a MathML string into the IDataObject
//set format
formatEtc.cfFormat = (Int16)dataFormatMathMLPres.Id; //<-this overflows. I verified that the only format that works is Presentation MAthML
formatEtc.dwAspect = System.Runtime.InteropServices.ComTypes.DVASPECT.DVASPECT_CONTENT;
formatEtc.lindex = -1;
formatEtc.ptd = (IntPtr)0;
formatEtc.tymed = TYMED.TYMED_HGLOBAL;
//set medium
ConnectSTGMEDIUM stgMedium = new ConnectSTGMEDIUM();
string mathEqn = "<math><mi>x</mi></math>";
stgMedium.unionmember = Marshal.StringToHGlobalAuto(mathEqn);
stgMedium.pUnkForRelease = 0;
//if now i write the equation to console from STGMEDIUM i see that after each char there is a null. Is this normal?
//now I try to set data in IDataObject and the OLE object
//I thought this set the data of the ole object to the MathML string I put in STGMEDIUM
oleDataObject.SetData(ref formatEtc, ref stgMedium, false);该应用程序现在崩溃,除了这个例外:
System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC&格式的
System.Runtime.InteropServices.COMException是未处理的Message=“无效的FORMATETC结构( HRESULT: 0x80040064 (DV_E_FORMATETC)的例外)”Source=“ErrorCode=-2147221404 StackTrace: at System.Runtime.InteropServices.COMException format,STGMEDIUM& medium”)
我不知道这意味着什么,但我认为这可能与formatEtc.cfFormat = (Int16)dataFormatMathMLPres.Id;有关,因为ID是50000,不适合短(cfFormat是短),所以它溢出到-15000之类的东西。
发布于 2011-11-25 16:15:15
我已经解决了类似的问题,将它从未签名的值转换成有符号的值。这意味着如果值(dataFormatMathMLPres.Id)大于32767。使用(dataFormatMathMLPres.Id - 65536)代替。它将适合签署的短。
https://stackoverflow.com/questions/1350120
复制相似问题