wolfgangimig / joa

Java Library for Developing Microsoft Outlook Add-ins
MIT License
12 stars 12 forks source link

How to invoke onQuit() after Outlook closing? #8

Open antCraft opened 6 years ago

antCraft commented 6 years ago

Hello. Can you explain to me how the onQuit () method works. Because in my case, the javaw.exe process does not terminated after closing the Outlook window, and the onQuit method is never called. Thank you!

@CoClass(progId = "JoaAddin1.Class", guid = "{ef6716de-9e55-44af-b5a7-3e974f2d3a04}") @DeclAddin(friendlyName = "Change Management", description = "Change Management", application = OfficeApplication.Outlook, loadBehavior = LoadBehavior.LoadOnStart)

public class JoaAddin1 extends OutlookAddin {

    private static Starter starter;
    private final IconManager ribbonIcons;

public JoaAddin1() {
    Globals.setThisAddin(this);
    ribbonIcons = new IconManager(this);

}

@Override
public void onQuit() throws ComException {

    super.onQuit();
}

public Dispatch onSmileButton2GetImage(IRibbonControl control) { 
            Dispatch picdisp = ribbonIcons.get("MyHappyFaceIcon1.png"); 
            return picdisp; 

     } 

public void onJoaTaskPaneClicked(Dispatch ribbonControl) {

           starter = new Starter();

            Object parentW =  getApplication().ActiveWindow();

            starter.showAsync(parentW, (taskpane, ex) -> );

}

wolfgangimig commented 6 years ago

Outlook should call the onQuit method if it is closing. Sometimes, it continues to run in background and this might delay the time the method is called.

antCraft commented 6 years ago

I'm sorry for disturbing you but for me it's very important to solve problem with listening Outlook actions. I'm newbie in Java and i try to create Addin with joa library. I created application and it's works but i have two problems.

  1. Main problem: i can't understand how method's like "onQuit" works and how to check on that stage it breaks. It's looks like that my Addin dosn't listen Outlook actions.
  2. Second question: is it possible to start Addin window separately from main Outlook window.
wolfgangimig commented 6 years ago
  1. The native part of JOA library binds to Oultook's COM events and forwards invocations to the Java part. Are you sure to start your Add-in in Eclipse -b-e-f-o-r-e- you start Outlook? Otherwise, Outlook starts a separate instance of your Add-in which does not run in the debugger. Set a breakpoint in your Add-ins Construtor. Does the debugger stop on this breakpoint?
  2. No
antCraft commented 6 years ago

I don't run the program directly. After Add-in registration, process javaw.exe run automatically when outlook load his Add-ins. But even if I run Add-in manually before start Outlook it's gives same result. Methods like "onAddInsUpdate" or "onStartupComplete" are woks, but methods like "onBeginShutdown" or "onDisconnection" and ect. doesn't works. They are works only if call them manually. In your library I found class DispatchImpl that has method:

public void _fireEvent(Class listenerClass, Consumer action) { ConnectionPoint listeners = getConnectionPointContainer().findConnectionPoint(listenerClass); if (listeners != null) { listeners.forEach(action); } }

In my Add-in I call: getConnectionPointContainer().getAllConnectionPointGuids() and it's returns empty array. Is it possible that this is the reason for the incorrect work? Outlook 2010. Thank you in advance!