@Before public void before() { HRESULT hr = Ole32.INSTANCE.CoInitialize(null); COMUtils.checkRC(hr); // Create word object CLSID clsid = new CLSID("{000209FF-0000-0000-C000-000000000046}"); this.ppWordApp = new PointerByReference(); hr = Ole32.INSTANCE.CoCreateInstance( clsid, null, WTypes.CLSCTX_SERVER, IDispatch.IID_IDISPATCH, this.ppWordApp); COMUtils.checkRC(hr); }
@After public void after() { // Close Word Dispatch d = new Dispatch(this.ppWordApp.getValue()); DISPID dispIdMember = new DISPID(1105); // Quit REFIID.ByValue riid = new REFIID.ByValue(Guid.IID_NULL); LCID lcid = Kernel32.INSTANCE.GetSystemDefaultLCID(); WinDef.WORD wFlags = new WinDef.WORD(1); DISPPARAMS.ByReference pDispParams = new DISPPARAMS.ByReference(); VARIANT.ByReference pVarResult = new VARIANT.ByReference(); IntByReference puArgErr = new IntByReference(); EXCEPINFO.ByReference pExcepInfo = new EXCEPINFO.ByReference(); d.Invoke(dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); Ole32.INSTANCE.CoUninitialize(); }