Re: Using GetActiveObject of OLEAUT32.DLL

Georg Ragaller <[email protected]>
Newsgroups gmane.comp.windows.devel.jawin
Message-ID <LISTSERV%[email protected]>
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.