Re: Using GetActiveObject of OLEAUT32.DLL

Deerwood McCord Jr <[email protected]>
Newsgroups gmane.comp.windows.devel.jawin
Message-ID <LISTSERV%[email protected]>
How do I get a DispatchPtr from here? Example
connecting to an already running word app. I want
the DisPatchPtr for Word.

example is CreateWord but I want Already running Instance.

 public static void main(String[] args) {
  try {
   Ole32.CoInitialize();
   DispatchPtr app = new
DispatchPtr("Word.Application");
   app.put("Visible", true);
   Ole32.CoUninitialize();
  } catch (Exception e) {
   e.printStackTrace();
  }



On Thu, 14 Apr 2005 01:55:29 -0400, Georg Ragaller <[email protected]>
wrote:

>Code for those who are interested ...
>
>//---- START OleAut32.java
>package org.jawin.win32;
>
>import org.jawin.*;
>import org.jawin.io.*;
>import java.io.*;
>import org.jawin.constants.WellKnownGUIDs;
>import org.jawin.marshal.GenericStub;
>
>public class OleAut32 {
>
>    private static final FuncPtr funcGetActiveObject;
>    private static final String instrGetActiveObject = "P16kA:H:L8N|4UU|";
>    private static final int stackSizeGetActiveObject = 12;
>
>    static {
>        try {
>            String oleaut32Dll = "OLEAUT32.DLL";
>            funcGetActiveObject = new FuncPtr
>(oleaut32Dll, "GetActiveObject");
>        } catch (COMException ce) {
>            throw new COMError("Unable to load OleAut32 entry points (" +
>ce.getMessage() + ")");
>        }
>    }
>
>    private OleAut32() {
>    }
>
>    public static IUnknown GetActiveObject(String progID)
>        throws COMException
>    {
>        try {
>            //--- needs a package private CLSIDFromProgID (orig. version in
>Ole32.java is private)
>            GUID clsid = Ole32.CLSIDFromProgID(progID);
>
>            Ole32.CoCreateInstance
>(clsid,Ole32.CLSCTX_ALL,WellKnownGUIDs.IID_IUnknown);
>
>            System.out.println(clsid);
>            System.out.flush();
>
>            NakedByteStream nbs = new NakedByteStream();
>            LittleEndianOutputStream baos = new LittleEndianOutputStream
>(nbs);
>            clsid.marshal(baos, null);
>            byte[] result = funcGetActiveObject.invoke(instrGetActiveObject,
>
>stackSizeGetActiveObject,
>                                                       nbs,
>                                                       null,
>
>ReturnFlags.CHECK_HRESULT);
>
>            return (IUnknown) IdentityManager.getCOMPtr(result, 0,
>WellKnownGUIDs.IID_IUnknown);
>        } catch (IOException ioe) {
>            throw new COMException(ioe);
>        }
>    }
>
>}
>//---- END
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.