com.jniwrapper.win32.com
Class ComFunctions

java.lang.Object
  extended bycom.jniwrapper.util.FunctionCache
      extended bycom.jniwrapper.win32.WinFunctionCache
          extended bycom.jniwrapper.win32.com.ComFunctions

public class ComFunctions
extends WinFunctionCache

This class provides wrappers for functions from OLEAUT32 library and service routines for JNIWrapper COM integration.


Method Summary
static void coCancelCall(int threadId, int timeout)
          Requests cancellation of an outbound DCOM method call pending on a specified thread.
static GUID coCreateGuid()
          Returns GUID, unique identifier associated with a COM class, and interface.
static IUnknown coCreateInstance(CLSID clsid, IUnknown pUnkOuter, ClsCtx dwClsContext)
          Creates a COM object of a specified class.
static void coCreateInstance(CLSID clsid, IUnknown pUnkOuter, ClsCtx dwClsContext, IID iid, IUnknown pReqInterface)
          Creates a COM object of a specified class.
static void coCreateInstance(CLSID clsid, IUnknown pUnkOuter, ClsCtx dwClsContext, IUnknown pReqInterface)
          Creates a COM object of a specified class.
static void coCreateInstanceEx(CLSID clsid, IUnknown pUnkOuter, ClsCtx dwClsContext, CoServerInfo serverInfo, IUnknownImpl pReqInterface)
          Creates a COM object of a specified class.
static void coFreeLibrary(Handle libraryHandle)
          Frees the specified library.
static void coFreeUnusedLibraries()
          Unloads all libraries that are no longer in use.
static void coGetClassObject(CLSID clsid, ClsCtx dwClsContext, Pointer.Void pvReserved, IUnknown ppv)
          Returns a pointer to the interface for a class object associated with a COM class.
static void coGetObject(java.lang.String name, IUnknownImpl ppv)
          Converts a display name into a moniker that identifies the object named, and then binds to the object identified by the moniker.
static void coInitialize()
          Initializes a COM library for the current thread using a single-thread appartment concurrency model.
static void coInitializeEx(CoInit value)
          Initializes a COM library for the current thread using the passed concurrency model specification.
static Handle coLoadLibrary(java.io.File library)
          Loads the specified library into the current process.
static UInt32 coRegisterClassObject(CLSID clsid, IUnknown pUnk, ClsCtx dwClsContext, RegCls flags)
          Registers EXE class object so that other applications can connect to it.
static IMessageFilterImpl coRegisterMessageFilter(IMessageFilterImpl msgFilter)
          Registers with OLE the instance of an IMessageFilter interface, which is to be used for handling concurrency issues on the current thread.
static void coRevokeClassObject(UInt32 dwRegister)
          Informs OLE that a class object previously registered with the coRegisterClassObject(com.jniwrapper.win32.com.types.CLSID, com.jniwrapper.win32.com.IUnknown, com.jniwrapper.win32.com.types.ClsCtx, com.jniwrapper.win32.com.types.RegCls) function is no longer available for use.
static Pointer.Void coTaskMemAlloc(ULongInt cb)
          Allocates a block of task memory.
static void coTaskMemFree(Pointer.Void pv)
          Frees a block of task memory previously allocated through a call to the coTaskMemAlloc(com.jniwrapper.ULongInt) or coTaskMemRealloc(com.jniwrapper.Pointer.Void, com.jniwrapper.ULongInt) function.
static void coTaskMemFree(Pointer pointer)
          Frees a block of task memory previously allocated through a call to the coTaskMemAlloc(com.jniwrapper.ULongInt) or coTaskMemRealloc(com.jniwrapper.Pointer.Void, com.jniwrapper.ULongInt) function.
static Pointer.Void coTaskMemRealloc(Pointer.Void pv, ULongInt cb)
          Changes the size of a previously allocated block of task memory.
static void coUninitialize()
          Closes a COM library for the current thread and performs all necessary clean-up actions.
static IMoniker createClassMoniker(CLSID clsid)
          Creates a class moniker that refers to the given class.
static ICreateErrorInfo createErrorInfo()
          Creates an instance of a generic error object.
static IMoniker createFileMoniker(java.io.File filePath)
          Creates a file moniker based on the specified path.
static IMoniker createGenericComposite(IMoniker first, IMoniker rest)
          Performs a generic composition of two monikers and supplies a pointer to the resulting composite moniker.
static IMoniker createItemMoniker(java.lang.String delimiter, java.lang.String item)
          Creates an item moniker that identifies an object within a containing object (typically a compound document).
static IMoniker createObjrefMoniker(IUnknown unk)
          Creates an OBJREF moniker based on a pointer to an object.
static IMoniker createPointerMoniker(IUnknown unk)
          Creates a pointer moniker based on a pointer to an object.
static IUnknown getActiveObject(CLSID clsid)
          Retrieves a running object that has been registered with OLE.
static CLSID getClassFromFile(java.lang.String fileName)
          Returns CLSID associated with a filename.
static IErrorInfo getErrorInfo()
          This function retrieves the error information pointer set by the previous call to SetErrorInfo in the current logical thread.
static HResult getErrorInfo(IErrorInfoImpl resErrorInfo)
          This function retrieves the error information pointer set by the previous call to SetErrorInfo in the current logical thread.
static ComFunctions getInstance()
           
static IRunningObjectTable getRunningObjectTable()
          Supplies a pointer to the IRunningObjectTable interface on the local Running Object Table (ROT).
static long registerActiveObject(IUnknown unknown, CLSID clsid, boolean strong)
          Registers an object as the active object for its class.
static void revokeActiveObject(long handle)
          Ends an object's status as active.
static void setErrorInfo(IErrorInfo errinfo)
          Sets the error information object for the current logical thread of execution.
static BStr sysAllocString(BStr str)
          Allocates a new string and copies the passed string into it
static void sysFreeString(BStr str)
          Deallocates a string allocated previously by sysAllocString(com.jniwrapper.win32.automation.types.BStr)
 
Methods inherited from class com.jniwrapper.win32.WinFunctionCache
isUnicode, setUnicode, setupEncoding
 
Methods inherited from class com.jniwrapper.util.FunctionCache
getFunction, getVariable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ComFunctions getInstance()

coInitialize

public static void coInitialize()
                         throws ComException
Initializes a COM library for the current thread using a single-thread appartment concurrency model.

Throws:
ComException - Microsoft COM SDK documentation

coInitializeEx

public static void coInitializeEx(CoInit value)
Initializes a COM library for the current thread using the passed concurrency model specification.

Parameters:
value - concurrency model specification.
See Also:
Microsoft COM SDK Documentation

coUninitialize

public static void coUninitialize()
Closes a COM library for the current thread and performs all necessary clean-up actions.

See Also:
Microsoft COM SDK Documentation

coCreateInstance

public static void coCreateInstance(CLSID clsid,
                                    IUnknown pUnkOuter,
                                    ClsCtx dwClsContext,
                                    IUnknown pReqInterface)
                             throws ComException
Creates a COM object of a specified class.

Parameters:
clsid - CLSID associated with a COM class.
pUnkOuter - a pointer to IUnknown interface for an aggregate object.
dwClsContext - context in which the executable code is run.
pReqInterface - a pointer to the interface for a created object. Both the value passed to the method and the returned value point to the same interface.
Throws:
ComException - Microsoft COM SDK Documentation

coCreateInstance

public static void coCreateInstance(CLSID clsid,
                                    IUnknown pUnkOuter,
                                    ClsCtx dwClsContext,
                                    IID iid,
                                    IUnknown pReqInterface)
                             throws ComException
Creates a COM object of a specified class.

Parameters:
clsid - CLSID associated with a COM class.
pUnkOuter - a pointer to IUnknown interface for an aggregate object.
dwClsContext - context in which the executable code is run.
iid - identifier of the interface to be used to communicate with the object.
pReqInterface - a pointer to the interface for a created object. Both the value passed to the method and the returned value point to the same interface.
Throws:
ComException - Microsoft COM SDK Documentation

coCreateInstanceEx

public static void coCreateInstanceEx(CLSID clsid,
                                      IUnknown pUnkOuter,
                                      ClsCtx dwClsContext,
                                      CoServerInfo serverInfo,
                                      IUnknownImpl pReqInterface)
Creates a COM object of a specified class.

Parameters:
clsid - CLSID associated with a COM class.
pUnkOuter - a pointer to IUnknown interface for an aggregate object.
dwClsContext - context in which the executable code is run.
serverInfo - information about the computer on which to instantiate the object. May be NULL
pReqInterface - a pointer to the interface for a created object. Both the value passed to the method and the returned value point to the same interface.
Throws:
ComException - Microsoft COM SDK Documentation

coGetClassObject

public static void coGetClassObject(CLSID clsid,
                                    ClsCtx dwClsContext,
                                    Pointer.Void pvReserved,
                                    IUnknown ppv)
                             throws ComException
Returns a pointer to the interface for a class object associated with a COM class.

Parameters:
clsid - CLSID associated with a COM class.
dwClsContext - context in which the executable code is run.
pvReserved - a pointer to the computer on which to instantiate a class object.
ppv - a pointer to the interface for a class object.
Throws:
ComException - Microsoft COM SDK Documentation

coGetObject

public static void coGetObject(java.lang.String name,
                               IUnknownImpl ppv)
Converts a display name into a moniker that identifies the object named, and then binds to the object identified by the moniker.

Parameters:
name - display name
ppv - interface to be created
See Also:
Microsoft COM SDK Documentation

coRegisterClassObject

public static UInt32 coRegisterClassObject(CLSID clsid,
                                           IUnknown pUnk,
                                           ClsCtx dwClsContext,
                                           RegCls flags)
                                    throws ComException
Registers EXE class object so that other applications can connect to it.

Parameters:
clsid - CLSID associated with a COM class.
pUnk - a pointer to unknown interface for a class object of the registered class.
dwClsContext - context in which the executable code is run.
flags - a type of connection to a class object.
Returns:
value that identifies a registered class object.
Throws:
ComException - Microsoft COM SDK Documentation.

coRevokeClassObject

public static void coRevokeClassObject(UInt32 dwRegister)
                                throws ComException
Informs OLE that a class object previously registered with the coRegisterClassObject(com.jniwrapper.win32.com.types.CLSID, com.jniwrapper.win32.com.IUnknown, com.jniwrapper.win32.com.types.ClsCtx, com.jniwrapper.win32.com.types.RegCls) function is no longer available for use.

Parameters:
dwRegister - a value previously returned by the coRegisterClassObject(com.jniwrapper.win32.com.types.CLSID, com.jniwrapper.win32.com.IUnknown, com.jniwrapper.win32.com.types.ClsCtx, com.jniwrapper.win32.com.types.RegCls) method.
Throws:
ComException - Microsoft COM SDK Documentation

coCreateInstance

public static IUnknown coCreateInstance(CLSID clsid,
                                        IUnknown pUnkOuter,
                                        ClsCtx dwClsContext)
                                 throws ComException
Creates a COM object of a specified class.

Parameters:
clsid - CLSID associated with a COM class.
pUnkOuter - a pointer to the IUnknown interface for an aggregate object.
dwClsContext - context in which the executable code is run.
Returns:
a pointer to the IUnknown interface for a created object.
Throws:
ComException - Microsoft COM SDK Documentation

coCreateGuid

public static GUID coCreateGuid()
                         throws ComException
Returns GUID, unique identifier associated with a COM class, and interface.

Returns:
GUID, unique identifier associated with a COM class, and interface.
Throws:
ComException - Microsoft COM SDK Documentation

sysAllocString

public static BStr sysAllocString(BStr str)
Allocates a new string and copies the passed string into it

Parameters:
str - A zero-terminated string to copy.
Returns:
If successful, returns a BSTR containing the string.
See Also:
Microsoft COM SDK Documentation

sysFreeString

public static void sysFreeString(BStr str)
Deallocates a string allocated previously by sysAllocString(com.jniwrapper.win32.automation.types.BStr)

Parameters:
str - Previously allocated BSTR. If bstr is NULL, the function simply returns.
See Also:
Microsoft COM SDK Documentation

coTaskMemAlloc

public static Pointer.Void coTaskMemAlloc(ULongInt cb)
Allocates a block of task memory.

Parameters:
cb - Size, in bytes, of the memory block to be allocated.
Returns:
Allocated memory block (if memory block allocated successfully), NULL otherwise.
See Also:
Microsoft COM SDK Documentation

coTaskMemRealloc

public static Pointer.Void coTaskMemRealloc(Pointer.Void pv,
                                            ULongInt cb)
Changes the size of a previously allocated block of task memory.

Parameters:
pv - Pointer to the memory block to be reallocated.
cb - Size, in bytes, of the memory block to be reallocated.
Returns:
Reallocated memory block (if memory block allocated successfully), NULL otherwise.
See Also:
Microsoft COM SDK Documentation

coTaskMemFree

public static void coTaskMemFree(Pointer.Void pv)
Frees a block of task memory previously allocated through a call to the coTaskMemAlloc(com.jniwrapper.ULongInt) or coTaskMemRealloc(com.jniwrapper.Pointer.Void, com.jniwrapper.ULongInt) function.

Parameters:
pv - Pointer to the memory block to be freed.
See Also:
Microsoft COM SDK Documentation

coTaskMemFree

public static void coTaskMemFree(Pointer pointer)
Frees a block of task memory previously allocated through a call to the coTaskMemAlloc(com.jniwrapper.ULongInt) or coTaskMemRealloc(com.jniwrapper.Pointer.Void, com.jniwrapper.ULongInt) function.

Parameters:
pointer - Pointer to the memory block to be freed.
See Also:
Microsoft COM SDK Documentation

getClassFromFile

public static CLSID getClassFromFile(java.lang.String fileName)
                              throws ComException
Returns CLSID associated with a filename.

Parameters:
fileName - a filename for which CLSID is returned.
Returns:
CLSID associated with a filename.
Throws:
ComException - Microsoft COM SDK Documentation

getActiveObject

public static IUnknown getActiveObject(CLSID clsid)
Retrieves a running object that has been registered with OLE.

Parameters:
clsid - a class identifier of the active object from the OLE registration database.
Returns:
returns a requested active object.
See Also:
Microsoft COM SDK Documentation

registerActiveObject

public static long registerActiveObject(IUnknown unknown,
                                        CLSID clsid,
                                        boolean strong)
                                 throws ComException
Registers an object as the active object for its class.

Parameters:
unknown - interface of the active object
clsid - CLSID of the active object
strong - flag that controls registration of the object. Value true corresponds to #ACTIVEOBJECT_STRONG and false to #ACTIVEOBJECT_WEAK native constants
Returns:
handle of registered object, which you need to pass to revokeActiveObject(long) method
Throws:
ComException - Microsoft COM SDK Documentation

revokeActiveObject

public static void revokeActiveObject(long handle)
                               throws ComException
Ends an object's status as active.

Parameters:
handle - handle previously returned by registerActiveObject(com.jniwrapper.win32.com.IUnknown, com.jniwrapper.win32.com.types.CLSID, boolean)) method.
Throws:
ComException - Microsoft COM SDK Documentation

coCancelCall

public static void coCancelCall(int threadId,
                                int timeout)
                         throws ComException
Requests cancellation of an outbound DCOM method call pending on a specified thread.

Parameters:
threadId - Identifier of the thread on which the pending DCOM call is to be canceled.
timeout - Number of seconds CoCancelCall waits for the server to complete the outbound call.
Throws:
ComException - Microsoft COM SDK Documentation

coLoadLibrary

public static Handle coLoadLibrary(java.io.File library)
Loads the specified library into the current process.

Parameters:
library - library file
Returns:
library handle
Since:
2.4
See Also:
Microsoft COM SDK Documentation

coFreeLibrary

public static void coFreeLibrary(Handle libraryHandle)
Frees the specified library.

Parameters:
libraryHandle - library handle to be freed
Since:
2.4
See Also:
Microsoft COM SDK Documentation

coFreeUnusedLibraries

public static void coFreeUnusedLibraries()
Unloads all libraries that are no longer in use.

Since:
2.4
See Also:
Microsoft COM SDK Documentation

getErrorInfo

public static HResult getErrorInfo(IErrorInfoImpl resErrorInfo)
This function retrieves the error information pointer set by the previous call to SetErrorInfo in the current logical thread.

Parameters:
resErrorInfo - system-implemented generic error object
Returns:
If successful, the function returns the HRESULT value S_OK. If there was no error object to return, the function returns S_FALSE.
Since:
2.5.1
See Also:
Microsoft COM SDK Documentation

getErrorInfo

public static IErrorInfo getErrorInfo()
                               throws ComException
This function retrieves the error information pointer set by the previous call to SetErrorInfo in the current logical thread.

Returns:
system-implemented generic error object
Throws:
ComException - Microsoft COM SDK Documentation
Since:
2.5.1

setErrorInfo

public static void setErrorInfo(IErrorInfo errinfo)
                         throws ComException
Sets the error information object for the current logical thread of execution.

Parameters:
errinfo - error object.
Throws:
ComException - Microsoft COM SDK Documentation
Since:
2.5.1

createErrorInfo

public static ICreateErrorInfo createErrorInfo()
                                        throws ComException
Creates an instance of a generic error object.

Returns:
system-implemented generic error object
Throws:
ComException - Microsoft COM SDK Documentation
Since:
2.5.1

coRegisterMessageFilter

public static IMessageFilterImpl coRegisterMessageFilter(IMessageFilterImpl msgFilter)
Registers with OLE the instance of an IMessageFilter interface, which is to be used for handling concurrency issues on the current thread. Only one message filter can be registered for each thread. Threads in multi-threaded apartments cannot have message filters.

Parameters:
msgFilter - interface on the message filter.
Returns:
previously registered message filter
Throws:
ComException - Microsoft COM SDK Documentation

getRunningObjectTable

public static IRunningObjectTable getRunningObjectTable()
                                                 throws ComException
Supplies a pointer to the IRunningObjectTable interface on the local Running Object Table (ROT).

Returns:
interface pointer to the local ROT.
Throws:
ComException - Microsoft COM SDK Documentation
Since:
2.5.1

createItemMoniker

public static IMoniker createItemMoniker(java.lang.String delimiter,
                                         java.lang.String item)
                                  throws ComException
Creates an item moniker that identifies an object within a containing object (typically a compound document).

Parameters:
delimiter - zero-terminated string containing the delimiter (typically "!") used to separate this item's display name from the display name of its containing object.
item - zero-terminated string indicating the containing object's name for the object being identified.
Returns:
interface pointer to the item moniker.
Throws:
ComException - Microsoft COM SDK Documentation
Since:
2.5.1

createClassMoniker

public static IMoniker createClassMoniker(CLSID clsid)
                                   throws ComException
Creates a class moniker that refers to the given class.

Parameters:
clsid - Reference to the CLSID of the object type to which this moniker binds.
Returns:
interface pointer to the new class moniker.
Throws:
ComException - Microsoft COM SDK Documentation
Since:
2.5.1

createFileMoniker

public static IMoniker createFileMoniker(java.io.File filePath)
                                  throws ComException
Creates a file moniker based on the specified path.

Parameters:
filePath - path on which this moniker is based.
Returns:
interface pointer to the new file moniker.
Throws:
ComException - Microsoft COM SDK Documentation
Since:
2.5.1

createObjrefMoniker

public static IMoniker createObjrefMoniker(IUnknown unk)
                                    throws ComException
Creates an OBJREF moniker based on a pointer to an object.

Parameters:
unk - interface on the object that the moniker is to represent.
Returns:
interface on the OBJREF moniker that was created.
Throws:
ComException - Microsoft COM SDK Documentation
Since:
2.5.1

createPointerMoniker

public static IMoniker createPointerMoniker(IUnknown unk)
                                     throws ComException
Creates a pointer moniker based on a pointer to an object.

Parameters:
unk - interface on the object to be identified by the resulting moniker.
Returns:
interface pointer to the new pointer moniker.
Throws:
ComException - Microsoft COM SDK Documentation
Since:
2.5.1

createGenericComposite

public static IMoniker createGenericComposite(IMoniker first,
                                              IMoniker rest)
                                       throws ComException
Performs a generic composition of two monikers and supplies a pointer to the resulting composite moniker.

Parameters:
first - moniker to be composed to the left of the moniker that "rest" points to. Can point to any kind of moniker, including a generic composite.
rest - moniker to be composed to the right of the moniker that "first" points to. Can point to any kind of moniker compatible with the type of the "rest" moniker, including a generic composite.
Returns:
interface pointer to the composite moniker object that is the result of composing "first" and "rest".
Throws:
ComException - Microsoft COM SDK Documentation
Since:
2.5.1