@Test
  public void Advise() {

    // query for ConnectionPointContainer
    Unknown unk = new Unknown(this.ppWordApp.getValue());
    PointerByReference ppCpc = new PointerByReference();
    IID cpcIID = new IID("{B196B284-BAB4-101A-B69C-00AA00341D07}");
    HRESULT hr = unk.QueryInterface(new REFIID.ByValue(cpcIID), ppCpc);
    COMUtils.checkRC(hr);
    ConnectionPointContainer cpc = new ConnectionPointContainer(ppCpc.getValue());

    // find connection point for Application_Events4
    IID appEvnts4 = new IID("{00020A01-0000-0000-C000-000000000046}");
    REFIID riid = new REFIID(appEvnts4.getPointer());
    PointerByReference ppCp = new PointerByReference();
    hr = cpc.FindConnectionPoint(riid, ppCp);
    COMUtils.checkRC(hr);
    ConnectionPoint cp = new ConnectionPoint(ppCp.getValue());
    IID cp_iid = new IID();
    hr = cp.GetConnectionInterface(cp_iid);
    COMUtils.checkRC(hr);

    Application_Events4 listener = new Application_Events4();

    DWORDByReference pdwCookie = new DWORDByReference();
    hr = cp.Advise(listener, pdwCookie);
    COMUtils.checkRC(hr);

    Assert.assertTrue(listener.QueryInterface_called);
  }
    @Override
    public HRESULT QueryInterface(REFIID.ByValue refid, PointerByReference ppvObject) {
      this.QueryInterface_called = true;
      if (null == ppvObject) {
        return new HRESULT(WinError.E_POINTER);
      }

      String s = refid.toGuidString();
      IID appEvnts4 = new IID("{00020A01-0000-0000-C000-000000000046}");
      REFIID.ByValue riid = new REFIID.ByValue(appEvnts4.getPointer());

      if (refid.equals(riid)) {
        return WinError.S_OK;
      }

      if (new Guid.IID(refid.getPointer()).equals(Unknown.IID_IUNKNOWN)) {
        ppvObject.setValue(this.getPointer());
        return WinError.S_OK;
      }

      if (new Guid.IID(refid.getPointer()).equals(Dispatch.IID_IDISPATCH)) {
        ppvObject.setValue(this.getPointer());
        return WinError.S_OK;
      }

      return new HRESULT(WinError.E_NOINTERFACE);
    }
  @Test
  public void FindConnectionPoint() {
    // query for ConnectionPointContainer
    Unknown unk = new Unknown(this.ppWordApp.getValue());
    PointerByReference ppCpc = new PointerByReference();
    IID cpcIID = new IID("{B196B284-BAB4-101A-B69C-00AA00341D07}");
    HRESULT hr = unk.QueryInterface(new REFIID.ByValue(cpcIID), ppCpc);
    COMUtils.checkRC(hr);
    ConnectionPointContainer cpc = new ConnectionPointContainer(ppCpc.getValue());

    // find connection point for Application_Events4
    IID appEvnts4 = new IID("{00020A01-0000-0000-C000-000000000046}");
    REFIID riid = new REFIID(appEvnts4.getPointer());
    PointerByReference ppCp = new PointerByReference();
    hr = cpc.FindConnectionPoint(riid, ppCp);
    COMUtils.checkRC(hr);
    ConnectionPoint cp = new ConnectionPoint(ppCp.getValue());
  }