Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interfaces from Ole32 and OleAuto #282

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
119 changes: 119 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/Ole32.java
Expand Up @@ -15,6 +15,7 @@
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.WString;
import com.sun.jna.platform.win32.COM.IUnknown;
import com.sun.jna.platform.win32.Guid.CLSID;
import com.sun.jna.platform.win32.Guid.GUID;
import com.sun.jna.platform.win32.WinDef.LPVOID;
Expand All @@ -35,6 +36,124 @@ public interface Ole32 extends StdCallLibrary {
Ole32 INSTANCE = (Ole32) Native.loadLibrary("Ole32", Ole32.class,
W32APIOptions.UNICODE_OPTIONS);

/**
* Identifies the version number of the installed OLE framework.
*
* @return A DWORD uniquely identifying the installed OLE framework build.
*/
int OleBuildVersion();

/**
* 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);

/**
* Creates a GUID, a unique 128-bit integer used for CLSIDs and interface
* identifiers.
Expand Down
158 changes: 157 additions & 1 deletion contrib/platform/src/com/sun/jna/platform/win32/OleAuto.java
Expand Up @@ -32,7 +32,6 @@
import com.sun.jna.platform.win32.WinDef.PVOID;
import com.sun.jna.platform.win32.WinDef.UINT;
import com.sun.jna.platform.win32.WinNT.HRESULT;
import com.sun.jna.platform.win32.COM.TypeLib;
import com.sun.jna.ptr.DoubleByReference;
import com.sun.jna.ptr.PointerByReference;
import com.sun.jna.win32.StdCallLibrary;
Expand Down Expand Up @@ -215,6 +214,163 @@ public interface OleAuto extends StdCallLibrary {
*/
HRESULT VariantClear(Pointer pvarg);

public static final short VARIANT_NOVALUEPROP = 0x01;
/** For VT_BOOL to VT_BSTR conversions, convert to "True"/"False" instead of "-1"/"0" */
public static final short VARIANT_ALPHABOOL = 0x02;
/** For conversions to/from VT_BSTR, passes LOCALE_NOUSEROVERRIDE to core coercion routines */
public static final short VARIANT_NOUSEROVERRIDE = 0x04;
public static final short VARIANT_CALENDAR_HIJRI = 0x08;
/** For VT_BOOL to VT_BSTR and back, convert to local language rather than English */
public static final short VARIANT_LOCALBOOL = 0x10;
/** SOUTHASIA calendar support */
public static final short VARIANT_CALENDAR_THAI = 0x20;
/** SOUTHASIA calendar support */
public static final short VARIANT_CALENDAR_GREGORIAN = 0x40;
/** NLS function call support */
public static final short VARIANT_USE_NLS = 0x80;

/**
* Converts a variant from one type to another.
* @param pvargDest [out] The destination variant. If this is the same as
* pvarSrc, the variant will be converted in place.
* @param pvarSrc [in] The variant to convert.
* @param wFlags Combination of the following flags
* <table>
* <thead>
* <tr><th><!--indent under wFlags comment--><div style="visibility: hidden">wFlags</div></th><th>Value</th><th>Meaning</th></tr>
* </thead>
* <tbody valign="top">
* <tr><th></th><td>{@link #VARIANT_NOVALUEPROP}</td><td>Prevents the function from attempting to coerce an object to a fundamental type by getting the Value property. Applications should set this flag only if necessary, because it makes their behavior inconsistent with other applications.</td></tr>
* <tr><th></th><td>{@link #VARIANT_ALPHABOOL}</td><td>Converts a {@link Variant#VT_BOOL VT_BOOL} value to a string containing either "True" or "False".</td></tr>
* <tr><th></th><td>{@link #VARIANT_NOUSEROVERRIDE}</td><td>For conversions to or from {@link Variant#VT_BSTR VT_BSTR}, passes LOCALE_NOUSEROVERRIDE to the core coercion routines.</td></tr>
* <tr><th></th><td>{@link #VARIANT_LOCALBOOL}</td><td>For conversions from {@link Variant#VT_BOOL VT_BOOL} to {@link Variant#VT_BSTR VT_BSTR} and back, uses the language specified by the locale in use on the local computer.</td></tr>
* </tbody>
* </table>
* @param vt The type to convert to. If the return code is {@link WinError#S_OK S_OK}, the vt
* field of the vargDest is guaranteed to be equal to this value.
* @return This function can return one of these values:
* <table>
* <thead>
* <tr><th>Return code</th><th>Description</th></tr>
* </thead>
* <tbody valign="top">
* <tr><td>{@link WinError#S_OK S_OK}</td><td>Success.</td></tr>
* <tr><td>{@link WinError#DISP_E_BADVARTYPE DISP_E_BADVARTYPE}</td><td>The variant type is not a valid type of variant.</td></tr>
* <tr><td>{@link WinError#DISP_E_OVERFLOW DISP_E_OVERFLOW}</td><td>The data pointed to by pvarSrc does not fit in the destination type.</td></tr>
* <tr><td>{@link WinError#DISP_E_TYPEMISMATCH DISP_E_TYPEMISMATCH}</td><td>The argument could not be coerced to the specified type.</td></tr>
* <tr><td>{@link WinError#E_INVALIDARG E_INVALIDARG}</td><td>One of the arguments is not valid.</td></tr>
* <tr><td>{@link WinError#E_OUTOFMEMORY E_OUTOFMEMORY}</td><td>Insufficient memory to complete the operation.</td></tr>
* </tbody>
* </table>
*</p>
* <b>Remarks</b>
*</p>
* The VariantChangeType function handles coercions between the fundamental
* types (including numeric-to-string and string-to-numeric coercions). The
* pvarSrc argument is changed during the conversion process. For example,
* if the source variant is of type {@link Variant#VT_BOOL VT_BOOL} and the
* destination is of type {@link Variant#VT_UINT VT_UINT}, the pvarSrc
* argument is first converted to {@link Variant#VT_I2 VT_I2} and then the
* conversion proceeds. A variant that has {@link Variant#VT_BYREF VT_BYREF}
* set is coerced to a value by obtaining the referenced value. An object is
* coerced to a value by invoking the object's Value property
* ({@link OaIdl#DISPID_VALUE DISPID_VALUE}).
*</p>
* Typically, the implementor of
* {@link com.sun.jna.platform.win32.COM.IDispatch#Invoke IDispatch.Invoke}
* determines which member is being accessed, and then calls
* VariantChangeType to get the value of one or more arguments. For example,
* if the IDispatch call specifies a SetTitle member that takes one string
* argument, the implementor would call VariantChangeType to attempt to
* coerce the argument to {@link Variant#VT_BSTR VT_BSTR}. If
* VariantChangeType does not return an error, the argument could then be
* obtained directly from the
* {@link Variant.VARIANT._VARIANT.__VARIANT#bstrVal bstrVal} field of the
* {@link Variant.VARIANT VARIANT}. If VariantChangeType returns
* {@link WinError#DISP_E_TYPEMISMATCH DISP_E_TYPEMISMATCH}, the implementor
* would set {@link com.sun.jna.platform.win32.COM.IDispatch#Invoke Invoke}
* <code> puArgErr</code> parameter referenced value to 0 (indicating the
* argument in error) and return DISP_E_TYPEMISMATCH from Invoke.
*</p>
* Arrays of one type cannot be converted to arrays of another type with
* this function.
*</p>
* <b>Note</b> The type of a {@link Variant.VARIANT VARIANT} should not be
* changed in the {@link DISPPARAMS#rgvarg rgvarg} array in place.
*/
HRESULT VariantChangeType(VARIANT pvargDest, VARIANT pvarSrc, short wFlags, VARTYPE vt);

/**
* Converts a variant from one type to another.
* @param pvargDest [out] The destination variant. If this is the same as
* pvarSrc, the variant will be converted in place.
* @param pvarSrc [in] The variant to convert.
* @param wFlags Combination of the following flags
* <table>
* <thead>
* <tr><th><!--indent under wFlags comment--><div style="visibility: hidden">wFlags</div></th><th>Value</th><th>Meaning</th></tr>
* </thead>
* <tbody valign="top">
* <tr><th></th><td>{@link #VARIANT_NOVALUEPROP}</td><td>Prevents the function from attempting to coerce an object to a fundamental type by getting the Value property. Applications should set this flag only if necessary, because it makes their behavior inconsistent with other applications.</td></tr>
* <tr><th></th><td>{@link #VARIANT_ALPHABOOL}</td><td>Converts a {@link Variant#VT_BOOL VT_BOOL} value to a string containing either "True" or "False".</td></tr>
* <tr><th></th><td>{@link #VARIANT_NOUSEROVERRIDE}</td><td>For conversions to or from {@link Variant#VT_BSTR VT_BSTR}, passes LOCALE_NOUSEROVERRIDE to the core coercion routines.</td></tr>
* <tr><th></th><td>{@link #VARIANT_LOCALBOOL}</td><td>For conversions from {@link Variant#VT_BOOL VT_BOOL} to {@link Variant#VT_BSTR VT_BSTR} and back, uses the language specified by the locale in use on the local computer.</td></tr>
* </tbody>
* </table>
* @param vt The type to convert to. If the return code is {@link WinError#S_OK S_OK}, the vt
* field of the vargDest is guaranteed to be equal to this value.
* @return This function can return one of these values:
* <table>
* <thead>
* <tr><th>Return code</th><th>Description</th></tr>
* </thead>
* <tbody valign="top">
* <tr><td>{@link WinError#S_OK S_OK}</td><td>Success.</td></tr>
* <tr><td>{@link WinError#DISP_E_BADVARTYPE DISP_E_BADVARTYPE}</td><td>The variant type is not a valid type of variant.</td></tr>
* <tr><td>{@link WinError#DISP_E_OVERFLOW DISP_E_OVERFLOW}</td><td>The data pointed to by pvarSrc does not fit in the destination type.</td></tr>
* <tr><td>{@link WinError#DISP_E_TYPEMISMATCH DISP_E_TYPEMISMATCH}</td><td>The argument could not be coerced to the specified type.</td></tr>
* <tr><td>{@link WinError#E_INVALIDARG E_INVALIDARG}</td><td>One of the arguments is not valid.</td></tr>
* <tr><td>{@link WinError#E_OUTOFMEMORY E_OUTOFMEMORY}</td><td>Insufficient memory to complete the operation.</td></tr>
* </tbody>
* </table>
*</p>
* <b>Remarks</b>
*</p>
* The VariantChangeType function handles coercions between the fundamental
* types (including numeric-to-string and string-to-numeric coercions). The
* pvarSrc argument is changed during the conversion process. For example,
* if the source variant is of type {@link Variant#VT_BOOL VT_BOOL} and the
* destination is of type {@link Variant#VT_UINT VT_UINT}, the pvarSrc
* argument is first converted to {@link Variant#VT_I2 VT_I2} and then the
* conversion proceeds. A variant that has {@link Variant#VT_BYREF VT_BYREF}
* set is coerced to a value by obtaining the referenced value. An object is
* coerced to a value by invoking the object's Value property
* ({@link OaIdl#DISPID_VALUE DISPID_VALUE}).
*</p>
* Typically, the implementor of
* {@link com.sun.jna.platform.win32.COM.IDispatch#Invoke IDispatch.Invoke}
* determines which member is being accessed, and then calls
* VariantChangeType to get the value of one or more arguments. For example,
* if the IDispatch call specifies a SetTitle member that takes one string
* argument, the implementor would call VariantChangeType to attempt to
* coerce the argument to {@link Variant#VT_BSTR VT_BSTR}. If
* VariantChangeType does not return an error, the argument could then be
* obtained directly from the
* {@link Variant.VARIANT._VARIANT.__VARIANT#bstrVal bstrVal} field of the
* {@link Variant.VARIANT VARIANT}. If VariantChangeType returns
* {@link WinError#DISP_E_TYPEMISMATCH DISP_E_TYPEMISMATCH}, the implementor
* would set {@link com.sun.jna.platform.win32.COM.IDispatch#Invoke Invoke}
* <code> puArgErr</code> parameter referenced value to 0 (indicating the
* argument in error) and return DISP_E_TYPEMISMATCH from Invoke.
*</p>
* Arrays of one type cannot be converted to arrays of another type with
* this function.
*</p>
* <b>Note</b> The type of a {@link Variant.VARIANT VARIANT} should not be
* changed in the {@link DISPPARAMS#rgvarg rgvarg} array in place.
*/
HRESULT VariantChangeType(VARIANT.ByReference pvargDest, VARIANT.ByReference pvarSrc, short wFlags, VARTYPE vt);

/**
* Creates a new array descriptor, allocates and initializes the data for
* the array, and returns a pointer to the new array descriptor.
Expand Down