Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
710 views
in Technique[技术] by (71.8m points)

windows - Load ink to a MathInputControl in C#

I'm trying to use use the LoadInk method of an mathinputcontrol but I can't figure out where to create the IIDispInk object from, as it just appears to be an interface.

http://msdn.microsoft.com/en-us/library/dd372605(VS.85).aspx

Any guidance would be highly appreciated.

Thanks :)

Edit: for clarity, here is my code so far [edit 2: by "so far", I mean of what's been added. Pretty much all the rest of my code can be found on SO under how to create the MIC in C#] (thanks to Hans Passant)

MSINKAUTLib.InkDispClass loadInkTest = new MSINKAUTLib.InkDispClass();

Stream stream = File.Open("C:\Tim\bytes.isf", FileMode.Open);
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
loadInkTest.Load(bytes);


ctrl.LoadInk((micautLib.IInkDisp)loadInkTest);

Unfortunately this throws exactly the same exception

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

C:Timytes.isf contain bytes saved from an InkPicture control which loads and saves this file file OK, so I assume that because the loadInkTest.Load() method did not throw an exception (normally it is not shy to do so) that it loaded the data OK. If there is a suggestion on a better (or more obvious) place to get the bytes, please let me know.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...