Skip to content

Commit

Permalink
Add Ole32 Functions:
Browse files Browse the repository at this point in the history
* OleBuildVersion
* OleInitialize
* OleUninitialize
* OleFlushClipboard
* OleRun
  • Loading branch information
matthiasblaesing committed Apr 1, 2017
1 parent 21404bf commit 2242c09
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
113 changes: 113 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/Ole32.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,117 @@ HRESULT CoCreateInstance(GUID rclsid, Pointer pUnkOuter, int dwClsContext,
*/
boolean CoIsHandlerConnected(Pointer pUnk);


/**
* Initializes the COM library on the current apartment, identifies the
* concurrency model as single-thread apartment (STA), and enables
* additional functionality described in the Remarks section below.
* Applications must initialize the COM library before they can call COM
* library functions other than CoGetMalloc and memory allocation functions.
* @param pvReserved Reserved; must be null.
* @return {@link WinError#S_OK S_OK} if the COM library and additional functionality were
* initialized successfully on this apartment.<p>
* {@link WinError#S_FALSE S_FALSE} if the COM library is already initialized on this apartment.<p>
* {@link WinError#OLE_E_WRONGCOMPOBJ OLE_E_WRONGCOMPOBJ} if the versions of COMPOBJ.DLL and OLE2.DLL on
* your machine are incompatible with each other.<p>
* {@link WinError#RPC_E_CHANGED_MODE RPC_E_CHANGED_MODE} if a previous call to CoInitializeEx specified
* the concurrency model for this apartment as
* multithread apartment (MTA). If running
* Windows 2000, this could also mean that a
* change from neutral threaded apartment to
* single threaded apartment occurred.
*/
HRESULT OleInitialize(Pointer pvReserved);

/**
* Closes the COM library on the apartment, releases any class factories,
* other COM objects, or servers held by the apartment, disables RPC on the
* apartment, and frees any resources the apartment maintains.
*
* Remarks:
* Call OleUninitialize on application shutdown, as the last COM library
* call, if the apartment was initialized with a call to
* {@link #OleInitialize}. OleUninitialize calls the CoUninitialize function
* internally to shut down the OLE Component Object(COM) Library.
*
* If the COM library was initialized on the apartment with a call to
* CoInitialize or CoInitializeEx, it must be closed with a call to
* CoUninitialize.
*
* The {@link #OleInitialize} and OleUninitialize calls must be balanced —
* if there are multiple calls to the {@link #OleInitialize} function, there
* must be the same number of calls to OleUninitialize: Only the
* OleUninitialize call corresponding to the {@link #OleInitialize} call
* that actually initialized the library can close it.
*/
void OleUninitialize();

/**
* Carries out the clipboard shutdown sequence. It also releases the
* IDataObject pointer that was placed on the clipboard by the
* OleSetClipboard function.
* @return {@link WinError#S_OK S_OK} on success.<p>
* {@link WinError#CLIPBRD_E_CANT_OPEN CLIPBRD_E_CANT_OPEN} The Windows OpenClipboard function used
* within OleFlushClipboard failed.<p>
* {@link WinError#CLIPBRD_E_CANT_CLOSE CLIPBRD_E_CANT_CLOSE} The Windows CloseClipboard function used
* within OleFlushClipboard failed.<p>
* <b>Remarks</b><p>
* OleFlushClipboard renders the data from a data object onto the clipboard
* and releases the IDataObject pointer to the data object. While the
* application that put the data object on the clipboard is running, the
* clipboard holds only a pointer to the data object, thus saving memory.
* If you are writing an application that acts as the source of a clipboard
* operation, you can call the OleFlushClipboard function when your
* application is closed, such as when the user exits from your application.
* Calling OleFlushClipboard enables pasting and paste-linking of OLE
* objects after application shutdown.
* Before calling OleFlushClipboard, you can easily determine if your data
* is still on the clipboard with a call to the OleIsCurrentClipboard
* function.
*
* OleFlushClipboard leaves all formats offered by the data transfer object,
* including the OLE 1 compatibility formats, on the clipboard so they are
* available after application shutdown. In addition to OLE 1 compatibility
* formats, these include all formats offered on a global handle medium (all
* except for TYMED_FILE) and formatted with a null target device. For
* example, if a data-source application offers a particular clipboard
* format (say cfFOO) on an IStorage object, and calls the OleFlushClipboard
* function, the storage object is copied into memory and the hglobal memory
* handle is put on the clipboard.
*
* To retrieve the information on the clipboard, you can call the
* OleGetClipboard function from another application, which creates a
* default data object, and the hglobal from the clipboard again becomes a
* storage object. Furthermore, the FORMATETC enumerator and the
* IDataObject::QueryGetData method would all correctly indicate that the
* original clipboard format (cfFOO) is again available on a TYMED_ISTORAGE.
*
* To empty the clipboard, call the OleSetClipboard function specifying a
* null value for its parameter. The application should call this when it
* closes if there is no need to leave data on the clipboard after shutdown,
* or if data will be placed on the clipboard using the standard Windows
* clipboard functions.
*/
HRESULT OleFlushClipboard();

/**
* Puts an OLE compound document object into the running state.
* @param pUnknown [in] Pointer to the {@link IUnknown IUnknown} interface
* on the object, with which it will query for a pointer to
* the IRunnableObject interface, and then call its Run method.
* @return This function returns on success.
* Other possible values include the following.<p>
* {@link WinError#OLE_E_CLASSDIFF OLE_E_CLASSDIFF} The source of an
* OLE link has been converted to a different class.<p>
* <B>Remarks</B><p>
* The OleRun function puts an object in the running state. The
* implementation of OleRun was changed in OLE 2.01 to coincide with the
* publication of the IRunnableObject interface. You can use OleRun and
* IRunnableObject::Run interchangeably. OleRun queries the object for a
* pointer to IRunnableObject. If successful, the function returns the
* results of calling the IRunnableObject::Run method.<p><p>
* For more information on using this function, see IRunnableObject::Run.
*/
HRESULT OleRun(Pointer pUnknown);

}
12 changes: 12 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/win32/Ole32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,16 @@ public void testCoTaskMemRealloc() {

Ole32.INSTANCE.CoTaskMemFree(ptr);
}

public void testOleFunctions() {
HRESULT initResult = Ole32.INSTANCE.OleInitialize(Pointer.NULL);

assertTrue(W32Errors.SUCCEEDED(initResult));

// For a real test, a test component will be needed
Ole32.INSTANCE.OleFlushClipboard();
Ole32.INSTANCE.OleRun(Pointer.NULL);

Ole32.INSTANCE.CoUninitialize();
}
}

0 comments on commit 2242c09

Please sign in to comment.