The major question seems to revolve around using dispatcher from an outside application. See this post:
viewtopic.php?f=20&t=72229&p=324928&hil ... 27#p324928
that has the quote:
What you experience with .uno:PasteSpecial is normal. Dispatcher commands are intended for user interface, not for programming.
We are also running the same surrounding code and paste content with MS-Word with zero crashing problems. The data can be pasted without error. So it is unique to this small code section, and probably has to do with using (or how we are trying to use) dispatcher. If you want a larger section of code, here is the code in the procedure that also includes (in the first section) the code that is working just fine now with MS-Word.
Code: Select all
BEGIN
IF GetWordProcessorRunning(aName) THEN
BEGIN
IF (0 <> POS(aName, kWordDisplayName)) THEN
BEGIN
TRY
Server := GetActiveOleObject('Word.Application');
IF pasteMatchStyle THEN
Server.ActiveDocument.Application.Selection.PasteSpecial(FALSE, FALSE, 0, FALSE, 2)
ELSE
Server.ActiveDocument.Application.Selection.Paste;
EXCEPT
return;
END;
END
ELSE
BEGIN
IF (0 <> POS(aName, kSWriter)) THEN
BEGIN
TRY
Server := CreateOleObject('com.sun.star.ServiceManager');
desktop := Server.createInstance('com.sun.star.frame.Desktop');
dispatcher := Server.createInstance('com.sun.star.frame.DispatchHelper');
dispatcher.executeDispatch(desktop.CurrentFrame, '.uno:Paste', '', 0, variantArray());
EXCEPT
return;
END;
END
ELSE
BEGIN
aWnd:= GetWordProcessorHandle;
IF aWnd <> 0 THEN
Send_CtrlV_ToAppHwnd(aWnd);
END;
END;
END;
END;
We are not loading the document. We are setting a Windows keyboard hook, so that the user can press a key combination in side Writer (or MS-Word, or Wordpad, or Notepad, or anything else) and our dialog pops up for the specialized text content we can serve up. We put their selection into the clipboard, and offer an option to press a button on the dialog that dismisses the dialog and automatically paste the content from the clipboard into the application.
This is very simple and has been working with MS-Word for some time now. We want to add support for Writer. Thus the question.
I should note that I also tried .uno:PageDialog as an alternative to paste and had problems. We also do not crash if I do not execute the dispatcher related calls. So I am given to think it is related to our use of dispatcher. Either in its use altogether, or in a blunder in how we used it. Which is why in the OP I asked:
I have searched about and seen a thread that seems to warn against using dispatcher from a 3rd party app. Is this the problem?
What are the possible solutions?
Is there another way to send a paste command into Writer?