Use Project + Add Reference, Browse tab. Navigate to c:program filescommon filesmicrosoft sharedink and select InkObj.dll. You can now create an instance of MSINKAUTLib.InkDispClass. It implements IInkDisp and has Save and Load methods.
You will have to cast the object to micautLib.IInkDisp, the interfaces come from different type libraries. And the clincher, you have to call the MathInputControl's Show() method first before using LoadInk(). Error reporting is miserable, everything is E_UNEXPECTED. The code I got to work:
var ctl = new micautLib.MathInputControl();
var ink = new MSINKAUTLib.InkDisp();
ink.Load(System.IO.File.ReadAllBytes("c:\temp\test.isf"));
var iink = (micautLib.IInkDisp)ink;
ctl.Show();
ctl.LoadInk(iink);
Plus event handlers for the Insert and Close event. And the glue to get the window in the right place.
Also beware that the micautLib type library has a dependency on the bit-ness of the machine. The troublemaker is the SetOwnerWindow() method, you really want to use it to prevent the dialog from disappearing behind another window. Its argument is declared as LONG_PTR, a type that is 32-bits on a 32-bit operating system, 64-bits on x64. The window handle. When you use Visual Studio, you will always get the 32-bit version of that method since VS is a 32-bit program.
If you plan on supporting 64-bit operating systems then you will have to build a separate version of your program. Starting with running the 64-bit version of Tlbimp.exe (not Visual Studio) to create the interop wrapper. So that the argument will be a 64-bit value and compatible with the window Handle you pass to the method.
Ah, the joys of COM. No real accident that this wasn't wrapped by Microsoft.Ink.dll :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…