using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Vanara.InteropServices;
namespace Vanara.PInvoke
{
public static partial class Ole32
{
/// Specify the role and creation context for the embedding helper.
[PInvokeData("ole2.h", MSDNShortId = "5c67b513-0692-4e0a-beab-8b514089699c")]
[Flags]
public enum EMBDHLP
{
///
/// Creates an embedding helper that can be used with DLL object applications; specifically, the helper exposes the caching
/// features of the default object handler.
///
EMBDHLP_INPROC_HANDLER = 0x0000,
/// Creates an embedding helper that is to be used as part of an in-process server. pCF cannot be NULL.
EMBDHLP_INPROC_SERVER = 0x0001,
/// Creates the secondary object using pCF immediately; if pCF is NULL, the standard proxy manager is used.
EMBDHLP_CREATENOW = 0x00000000,
///
/// Delays creation of the secondary object until it is needed (when the helper is put into the running state) to enhance speed
/// and memory use. pCF must not be NULL. The EMBDHLP_INPROC_HANDLER flag cannot be used with this flag.
///
EMBDHLP_DELAYCREATE = 0x00010000,
}
/// Flags for OleCreateEx.
[PInvokeData("ole2.h", MSDNShortId = "11f2703c-b596-4cb9-855a-d8cf4b947fae")]
[Flags]
public enum OLECREATE
{
///
OLECREATE_LEAVERUNNING = 1
}
/// Retrieves a pointer to the OLE implementation of IDataAdviseHolder on the data advise holder object.
///
/// Address of an IDataAdviseHolder pointer variable that receives the interface pointer to the new advise holder object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_OUTOFMEMORY
/// Insufficient memory for the operation.
///
///
///
///
/// Call CreateDataAdviseHolder in your implementation of IDataObject::DAdvise to get a pointer to the OLE implementation of
/// IDataAdviseHolder interface. With this pointer, you can then complete the implementation of IDataObject::DAdvise by
/// calling the IDataAdviseHolder::Advise method, which creates an advisory connection between the calling object and the data object.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-createdataadviseholder HRESULT CreateDataAdviseHolder(
// LPDATAADVISEHOLDER *ppDAHolder );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "a2114f2f-106a-4a26-ba94-1b40af90a0f3")]
public static extern HRESULT CreateDataAdviseHolder(out IDataAdviseHolder ppDAHolder);
///
/// Creates an advise holder object for managing compound document notifications. It returns a pointer to the object's OLE
/// implementation of the IOleAdviseHolder interface.
///
///
/// Address of IOleAdviseHolder pointer variable that receives the interface pointer to the new advise holder object.
///
/// This function returns S_OK on success and supports the standard return value E_OUTOFMEMORY.
///
/// The function CreateOleAdviseHolder creates an instance of an advise holder, which supports the OLE implementation of the
/// IOleAdviseHolder interface. The methods of this interface are intended to be used to implement the advisory methods of
/// IOleObject, and, when advisory connections have been set up with objects supporting an advisory sink, to send notifications of
/// changes in the object to the advisory sink. The advise holder returned by CreateOleAdviseHolder will suffice for the great
/// majority of applications. The OLE-provided implementation does not, however, support IOleAdviseHolder::EnumAdvise, so if you need
/// to use this method, you will need to implement your own advise holder.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-createoleadviseholder HRESULT CreateOleAdviseHolder(
// LPOLEADVISEHOLDER *ppOAHolder );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "f76e074e-6814-4735-9417-d5970e73089f")]
public static extern HRESULT CreateOleAdviseHolder(out IOleAdviseHolder ppOAHolder);
///
/// Carries out an OLE drag and drop operation.
/// Note You must call OleInitialize before calling this function.
///
/// Pointer to the IDataObject interface on a data object that contains the data being dragged.
///
/// Pointer to an implementation of the IDropSource interface, which is used to communicate with the source during the drag operation.
///
///
/// Effects the source allows in the OLE drag-and-drop operation. Most significant is whether it permits a move. The dwOKEffect and
/// pdwEffect parameters obtain values from the DROPEFFECT enumeration. For a list of values, see DROPEFFECT.
///
///
/// Pointer to a value that indicates how the OLE drag-and-drop operation affected the source data. The pdwEffect parameter is set
/// only if the operation is not canceled.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// DRAGDROP_S_DROP
/// The OLE drag-and-drop operation was successful.
///
/// -
/// DRAGDROP_S_CANCEL
/// The OLE drag-and-drop operation was canceled.
///
/// -
/// E_UNSPEC
/// Unexpected error occurred.
///
///
///
///
///
/// If you are developing an application that can act as a data source for an OLE drag-and-drop operation, you must call
/// DoDragDrop when you detect that the user has started an OLE drag-and-drop operation.
///
///
/// The DoDragDrop function enters a loop in which it calls various methods in the IDropSource and IDropTarget interfaces.
/// (For a successful drag-and-drop operation, the application acting as the data source must also implement IDropSource,
/// while the target application must implement IDropTarget.)
///
///
/// -
///
/// The DoDragDrop function determines the window under the current cursor location. It then checks to see if this window is a
/// valid drop target.
///
///
/// -
///
/// If the window is a valid drop target, DoDragDrop calls IDropTarget::DragEnter. This method supplies an effect code
/// indicating what would happen if the drop actually occurred. For a list of valid drop effects, see the DROPEFFECT enumeration.
///
///
/// -
///
/// DoDragDrop calls IDropSource::GiveFeedback with the effect code so that the drop source interface can provide appropriate
/// visual feedback to the user. The pDropSource pointer passed into DoDragDrop specifies the appropriate IDropSource interface.
///
///
/// -
/// DoDragDrop tracks mouse cursor movements and changes in the keyboard or mouse button state.
///
/// -
///
/// If there is a change in the keyboard or mouse button state, DoDragDrop calls IDropSource::QueryContinueDrag and determines
/// whether to continue the drag, to drop the data, or to cancel the operation based on the return value.
///
///
///
/// DoDragDrop does not support invoking drag and drop support when you handle touch or pen input.
///
/// To support touch or pen input, do not call DoDragDrop from your touch handler. Instead, call DoDragDrop from your
/// handler for those mouse messages that the system synthesizes upon touch input.
///
///
/// The application can identify synthesized messages by calling the GetMessageExtraInfo function. For more information about using
/// GetMessageExtraInfo to distinguish between mouse input and Windows Touch input, see Troubleshooting Applications.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-dodragdrop HRESULT DoDragDrop( IN LPDATAOBJECT pDataObj, IN
// LPDROPSOURCE pDropSource, IN DWORD dwOKEffects, OUT LPDWORD pdwEffect );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "095172ac-9e08-4797-b9da-41a4e5a61315")]
public static extern HRESULT DoDragDrop([In] IDataObject pDataObj, [In] IDropSource pDropSource, [In] DROPEFFECT dwOKEffects, out DROPEFFECT pdwEffect);
/// Determines whether the specified keystroke maps to an accelerator in the specified accelerator table.
/// A handle to the accelerator table.
/// The number of entries in the accelerator table.
/// A pointer to the keystroke message to be translated.
///
/// A pointer to a variable to receive the corresponding command identifier if there is an accelerator for the keystroke. This
/// parameter may be NULL.
///
///
/// If the message is for the object application, the return value is TRUE. If the message is not for the object and should be
/// forwarded to the container, the return value is FALSE.
///
///
///
/// While an object is active in-place, the object always has first chance to translate the keystrokes into accelerators. If the
/// keystroke corresponds to one of its accelerators, the object must not call the OleTranslateAccelerator function — even if its
/// call to the TranslateAccelerator function fails. Failure to process keystrokes in this manner can lead to inconsistent behavior.
///
///
/// If the keystroke is not one of the object's accelerators, then the object must call OleTranslateAccelerator to let the container
/// try its accelerator translation.
///
///
/// The object's server can call IsAccelerator to determine if the accelerator message belongs to it. Some servers do
/// accelerator translation on their own and do not call TranslateAccelerator. Those applications will not call IsAccelerator,
/// because they already have the information.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-isaccelerator BOOL IsAccelerator( IN HACCEL hAccel, IN int
// cAccelEntries, IN LPMSG lpMsg, OUT WORD *lpwCmd );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "2d09f81a-b422-4379-89c8-d50992ebb24c")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsAccelerator(HACCEL hAccel, int cAccelEntries, in MSG lpMsg, out ushort lpwCmd);
///
/// The OleConvertIStorageToOLESTREAM function converts the specified storage object from OLE 2 structured storage to the OLE
/// 1 storage object model but does not include the presentation data. This is one of several compatibility functions.
///
/// Pointer to the IStorage interface on the storage object to be converted to an OLE 1 storage.
///
/// Pointer to an OLE 1 stream structure where the persistent representation of the object is saved using the OLE 1 storage model.
///
/// This function supports the standard return value E_INVALIDARG, in addition to the following:
///
///
/// This function converts an OLE 2 storage object to OLE 1 format. The OLESTREAM structure code implemented for OLE 1 must be available.
///
///
/// On entry, the stream to which lpolestm points should be created and positioned just as it would be for an OleSaveToStream call.
/// On exit, the stream contains the persistent representation of the object using OLE 1 storage.
///
///
/// Note Paintbrush objects are dealt with differently from other objects because their native data is in device-independent
/// bitmap (DIB) format. When Paintbrush objects are converted using OleConvertIStorageToOLESTREAM, no presentation data is
/// added to the OLESTREAM structure. To include presentation data, use the OleConvertIStorageToOLESTREAMEx function instead.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleconvertistoragetoolestream HRESULT
// OleConvertIStorageToOLESTREAM( IN LPSTORAGE pstg, OUT LPOLESTREAM lpolestream );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "d100d32a-6559-4a7c-a0ae-780bc9d82611")]
public static extern HRESULT OleConvertIStorageToOLESTREAM([In] IStorage pstg, out OLESTREAM lpolestream);
///
/// The OleConvertIStorageToOLESTREAMEx function converts the specified storage object from OLE 2 structured storage to the
/// OLE 1 storage object model, including the presentation data. This is one of several functions included in Structured Storage to
/// ensure compatibility between OLE1 and OLE2.
///
/// Pointer to the IStorage interface on the storage object to be converted to an OLE 1 storage.
///
/// Format of the presentation data. May be NULL, in which case the lWidth, lHeight, dwSize, and pmedium parameters are ignored.
///
/// Width of the object presentation data in HIMETRIC units.
/// Height of the object presentation data in HIMETRIC units.
/// Size of the data, in bytes, to be converted.
/// Pointer to the STGMEDIUM structure for the serialized data to be converted.
///
/// Pointer to a stream where the persistent representation of the object is saved using the OLE 1 storage model.
///
/// This function supports the standard return value E_INVALIDARG, in addition to the following:
///
///
/// The OleConvertIStorageToOLESTREAMEx function converts an OLE 2 storage object to OLE 1 format. It differs from the
/// OleConvertIStorageToOLESTREAM function in that the OleConvertIStorageToOLESTREAMEx function also passes the presentation
/// data to the OLE 1 storage object, whereas the OleConvertIStorageToOLESTREAM function does not.
///
///
/// Because OleConvertIStorageToOLESTREAMEx can specify which presentation data to convert, it can be used by applications
/// that do not use OLE default caching resources but do use OLE's conversion resources.
///
///
/// The value of the tymed member of STGMEDIUM must be either TYMED_HGLOBAL or TYMED_ISTREAM; refer to the TYMED enumeration
/// for more information. The medium is not released by the OleConvertIStorageToOLESTREAMEx function.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleconvertistoragetoolestreamex HRESULT
// OleConvertIStorageToOLESTREAMEx( IN LPSTORAGE pstg, IN CLIPFORMAT cfFormat, IN LONG lWidth, IN LONG lHeight, IN DWORD dwSize, IN
// LPSTGMEDIUM pmedium, OUT LPOLESTREAM polestm );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "a6026b71-4223-40ab-b209-44531480db57")]
public static extern HRESULT OleConvertIStorageToOLESTREAMEx([In] IStorage pstg, CLIPFORMAT cfFormat, int lWidth, int lHeight, uint dwSize, in STGMEDIUM pmedium, out OLESTREAM polestm);
///
///
/// The OleConvertOLESTREAMToIStorage function converts the specified object from the OLE 1 storage model to an OLE 2
/// structured storage object without specifying presentation data.
///
/// Note This is one of several compatibility functions.
///
///
/// A pointer to a stream that contains the persistent representation of the object in the OLE 1 storage format.
///
/// A pointer to the IStorage interface on the OLE 2 structured storage object.
///
/// A pointer to the DVTARGETDEVICE structure that specifies the target device for which the OLE 1 object is rendered.
///
/// This function supports the standard return value E_INVALIDARG, in addition to the following:
///
///
/// This function converts an OLE 1 object to an OLE 2 structured storage object. Use this function to update OLE 1 objects to OLE 2
/// objects when a new version of the object application supports OLE 2.
///
///
/// On entry, the lpolestm parameter should be created and positioned just as it would be for an OleLoadFromStream function call. On
/// exit, the lpolestm parameter is positioned just as it would be on exit from an OleLoadFromStream function, and the pstg
/// parameter contains the uncommitted persistent representation of the OLE 2 storage object.
///
///
/// For OLE 1 objects that use native data for their presentation, the OleConvertOLESTREAMToIStorage function returns
/// CONVERT10_S_NO_PRESENTATION. On receiving this return value, callers should call IOleObject::Update to get the
/// presentation data so it can be written to storage.
///
///
/// Applications that do not use the OLE default caching resources, but use the conversion resources, can use an alternate function,
/// OleConvertOLESTREAMToIStorageEx, which can specify the presentation data to convert. In the
/// OleConvertOLESTREAMToIStorageEx function, the presentation data read from the OLESTREAM structure is passed out and
/// the newly created OLE 2 storage object does not contain a presentation stream.
///
/// The following procedure describes the conversion process using OleConvertOLESTREAMToIStorage.
/// Converting an OLE 1 object to an OLE 2 storage object
///
/// -
/// Create a root IStorage object by calling the StgCreateDocfile function (..., &pstg).
///
/// -
/// Open the OLE 1 file (using OpenFile or another OLE 1 technique).
///
/// -
/// Read from the file, using the OLE 1 procedure for reading files, until an OLE object is found.
///
/// -
/// Allocate an IStorage object from the root IStorage created in Step 1.
///
/// -
/// Repeat Step 3 until the file is completely read.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleconvertolestreamtoistorage HRESULT
// OleConvertOLESTREAMToIStorage( IN LPOLESTREAM lpolestream, OUT LPSTORAGE pstg, IN const DVTARGETDEVICE *ptd );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "8fed879c-5f97-4450-8259-da9643dd828c")]
public static extern HRESULT OleConvertOLESTREAMToIStorage(in OLESTREAM lpolestream, out IStorage pstg, in DVTARGETDEVICE ptd);
///
/// The OleConvertOLESTREAMToIStorageEx function converts the specified object from the OLE 1 storage model to an OLE 2
/// structured storage object including presentation data. This is one of several compatibility functions.
///
///
/// Pointer to the stream that contains the persistent representation of the object in the OLE 1 storage format.
///
/// Pointer to the OLE 2 structured storage object.
///
/// Pointer to where the format of the presentation data is returned. May be NULL, indicating the absence of presentation data.
///
/// Pointer to where the width value (in HIMETRIC) of the presentation data is returned.
/// Pointer to where the height value (in HIMETRIC) of the presentation data is returned.
/// Pointer to where the size in bytes of the converted data is returned.
/// Pointer to where the STGMEDIUM structure for the converted serialized data is returned.
/// This function returns HRESULT.
///
///
/// This function converts an OLE 1 object to an OLE 2 structured storage object. You can use this function to update OLE 1 objects
/// to OLE 2 objects when a new version of the object application supports OLE 2.
///
///
/// This function differs from the OleConvertOLESTREAMToIStorage function in that the presentation data read from the
/// OLESTREAM structure is passed out and the newly created OLE 2 storage object does not contain a presentation stream.
///
///
/// Since this function can specify which presentation data to convert, it can be used by applications that do not use OLE's default
/// caching resources but do use the conversion resources.
///
///
/// The tymed member of STGMEDIUM can only be TYMED_NULL or TYMED_ISTREAM. If it is TYMED_NULL, the data will be returned in a
/// global handle through the hGlobal member of STGMEDIUM, otherwise data will be written into the pstm member
/// of this structure.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleconvertolestreamtoistorageex HRESULT
// OleConvertOLESTREAMToIStorageEx( IN LPOLESTREAM polestm, OUT LPSTORAGE pstg, OUT CLIPFORMAT *pcfFormat, OUT LONG *plwWidth, OUT
// LONG *plHeight, OUT DWORD *pdwSize, OUT LPSTGMEDIUM pmedium );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "2e77fa0e-1d98-4c59-8d3c-65bd7235ec8f")]
public static extern HRESULT OleConvertOLESTREAMToIStorageEx(in OLESTREAM polestm, out IStorage pstg, out CLIPFORMAT pcfFormat, out int plwWidth, out int plHeight, out uint pdwSize, out STGMEDIUM pmedium);
///
/// Creates an embedded object identified by a CLSID. You use it typically to implement the menu item that allows the end user to
/// insert a new object.
///
/// CLSID of the embedded object that is to be created.
///
/// Reference to the identifier of the interface, usually IID_IOleObject (defined in the OLE headers as the interface identifier for
/// IOleObject), through which the caller communicates with the new object.
///
///
/// Value from the enumeration OLERENDER, indicating the locally cached drawing capabilities the newly created object is to have. The
/// OLERENDER value chosen affects the possible values for the pFormatEtc parameter.
///
///
/// Depending on which OLERENDER flag is used as the value of , this is a pointer to an FORMATETC
/// enumeration value. For restrictions, see the OLERENDER enumeration.
/// This parameter, along with the parameter, specifies what the new object can cache initially.
///
///
/// If you want OleCreate to call IOleObject::SetClientSite, pClientSite is the pointer to the IOleClientSite interface on the container.
/// The value can be NULL, in which case you must specifically call IOleClientSite::SetClientSite before attempting operations.
///
///
/// Pointer to an instance of the IStorage interface on the storage object.
/// This parameter cannot be NULL.
///
///
/// Pointer to the pointer variable that receives the interface pointer requested in .
/// Upon successful return, *ppvObject contains the requested interface pointer.
///
///
/// This function returns S_OK on success and supports the standard return value E_OUTOFMEMORY.
///
///
/// Return code
/// Description
///
/// -
/// E_OUTOFMEMORY
/// Insufficient memory for the operation.
///
///
///
///
///
/// The OleCreate function creates a new embedded object, and is typically called to implement the menu item Insert New
/// Object. When OleCreate returns, the object it has created is blank (contains no data), unless
/// is OLERENDER_DRAW or OLERENDER_FORMAT, and is loaded. Containers typically then call the OleRun function or IOleObject::DoVerb to
/// show the object for initial editing.
///
///
/// The parameter specifies the CLSID of the requested object. CLSIDs of registered objects are stored in
/// the system registry. When an application user selects Insert Object, a selection box allows the user to select the type of object
/// desired from those in the registry. When OleCreate is used to implement the Insert Object menu item, the CLSID associated
/// with the selected item is assigned to the parameter of OleCreate.
///
///
/// The parameter specifies the interface the client will use to communicate with the new object. Upon
/// successful return, the ppvObject parameter holds a pointer to the requested interface.
///
///
/// The created object's cache contains information that allows a presentation of a contained object when the container is opened.
/// Information about what should be cached is passed in the and pFormatetc values. When
/// OleCreate returns, the created object's cache is not necessarily filled. Instead, the cache is filled the first time the
/// object enters the running state. The caller can add additional cache control with a call to IOleCache::Cache after the return of
/// OleCreate and before the object is run. If is OLERENDER_DRAW or OLERENDER_FORMAT,
/// OleCreate requires that the object support the IOleCache interface. There is no such requirement for any other value of .
///
///
/// If pClientSite is non- NULL, OleCreate calls IOleObject::SetClientSite through the pClientSite pointer.
/// IOleClientSite is the primary interface by which an object requests services from its container. If pClientSite is NULL,
/// you must make a specific call to IOleObject::SetClientSite before attempting any operations.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreate HRESULT OleCreate( IN REFCLSID rclsid, IN REFIID riid,
// IN DWORD renderopt, IN LPFORMATETC pFormatEtc, IN LPOLECLIENTSITE pClientSite, IN LPSTORAGE pStg, OUT LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "00b7edd2-8e2e-4e0a-91a6-d966f6c8d456")]
public static extern HRESULT OleCreate(in Guid rclsid, in Guid riid, OLERENDER renderopt, in FORMATETC pFormatEtc, [In, Optional] IOleClientSite pClientSite, [In] IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
///
/// Creates a new instance of the default embedding handler. This instance is initialized so it creates a local server when the
/// embedded object enters the running state.
///
/// CLSID identifying the OLE server to be loaded when the embedded object enters the running state.
///
/// Pointer to the controlling IUnknown interface if the handler is to be aggregated; NULL if it is not to be aggregated.
///
///
/// Reference to the identifier of the interface, usually IID_IOleObject, through which the caller will communicate with the handler.
///
///
/// Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvObj contains the
/// requested interface pointer on the newly created handler.
///
/// This function returns NOERROR on success and supports the standard return value E_OUTOFMEMORY.
///
///
/// OleCreateDefaultHandler creates a new instance of the default embedding handler, initialized so it creates a local server
/// identified by the clsid parameter when the embedded object enters the running state. If you are writing a handler and want to use
/// the services of the default handler, call OleCreateDefaultHandler. OLE also calls it internally when the CLSID specified
/// in an object creation call is not registered.
///
///
/// If the given class does not have a special handler, a call to OleCreateDefaultHandler produces the same results as a call
/// to the CoCreateInstance function with the class context parameter assigned the value CLSCTX_INPROC_HANDLER.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreatedefaulthandler HRESULT OleCreateDefaultHandler( IN
// REFCLSID clsid, IN LPUNKNOWN pUnkOuter, IN REFIID riid, OUT LPVOID *lplpObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "ffe87012-b000-4ed7-b0b2-78ffdc794d3b")]
public static extern HRESULT OleCreateDefaultHandler(in Guid clsid, [MarshalAs(UnmanagedType.IUnknown), Optional] object pUnkOuter, in Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object lplpObj);
///
/// Creates an OLE embedding helper object using application-supplied code aggregated with pieces of the OLE default object handler.
/// This helper object can be created and used in a specific context and role, as determined by the caller.
///
/// CLSID of the class to be helped.
///
/// If the embedding helper is to be aggregated, pointer to the outer object's controlling IUnknown interface. If it is not to be
/// aggregated, although this is rare, the value should be NULL.
///
///
/// DWORD containing flags that specify the role and creation context for the embedding helper. For legal values, see the following
/// Remarks section.
///
///
/// Pointer to the IClassFactory interface on the class object the function uses to create the secondary object. In some situations,
/// this value may be NULL. For more information, see the following Remarks section.
///
/// Reference to the identifier of the interface desired by the caller.
///
/// Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvObj contains the
/// requested interface pointer on the newly created embedding helper.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_OUTOFMEMORY
/// Insufficient memory for the operation.
///
/// -
/// E_INVALIDARG
/// One or more parameters are invalid.
///
/// -
/// E_UNEXPECTED
/// An unexpected error has occurred.
///
/// -
/// E_NOINTERFACE
/// The provided interface identifier is invalid.
///
///
///
///
///
/// The OleCreateEmbeddingHelper function creates an object that supports the same interface implementations found in the
/// default handler, but which has additional hooks that allow it to be used more generally than just as a handler object. The
/// following two calls produce the same result:
///
///
/// The embedding helper is aggregatable; pUnkOuter is the controlling IUnknown of the aggregate of which the embedding helper is to
/// be a part. It is used to create a new instance of the OLE default handler, which can be used to support objects in various roles.
/// The caller passes a pointer to its IClassFactory implementation to OleCreateEmbeddingHelper. This object and the default
/// handler are then aggregated to create the new embedding helper object.
///
/// The OleCreateEmbeddingHelper function is usually used to support one of the following implementations:
///
/// -
///
/// An EXE object application that is being used as both a container and a server, and which supports inserting objects into itself.
/// For this case, CreateEmbeddingHelper allows the object to support the interfaces usually supported only in the handler. To
/// accomplish this, the application must first register its CLSID for different contexts, making two registration calls to the
/// CoRegisterClassObject function, rather than one, as follows:
///
///
/// -
///
/// A custom in-process object handler, in which case, the DLL creates the embedding helper by passing in a pointer to a private
/// implementation of IClassFactory in pCF.
///
///
///
///
/// The flags parameter indicates how the embedding helper is to be used and how and when the embedding helper is initialized. The
/// values for flags are obtained by OR-ing together values from the following table.
///
///
///
/// Values for flags Parameter
/// Purpose
///
/// -
/// EMBDHLP_INPROC_HANDLER
///
/// Creates an embedding helper that can be used with DLL object applications; specifically, the helper exposes the caching features
/// of the default object handler.
///
///
/// -
/// EMBDHLP_INPROC_SERVER
/// Creates an embedding helper that is to be used as part of an in-process server. pCF cannot be NULL.
///
/// -
/// EMBDHLP_CREATENOW
/// Creates the secondary object using pCF immediately; if pCF is NULL, the standard proxy manager is used.
///
/// -
/// EMBDHLP_DELAYCREATE
///
/// Delays creation of the secondary object until it is needed (when the helper is put into the running state) to enhance speed and
/// memory use. pCF must not be NULL. The EMBDHLP_INPROC_HANDLER flag cannot be used with this flag.
///
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreateembeddinghelper HRESULT OleCreateEmbeddingHelper( IN
// REFCLSID clsid, IN LPUNKNOWN pUnkOuter, IN DWORD flags, IN LPCLASSFACTORY pCF, IN REFIID riid, OUT LPVOID *lplpObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "5c67b513-0692-4e0a-beab-8b514089699c")]
public static extern HRESULT OleCreateEmbeddingHelper(in Guid clsid, [MarshalAs(UnmanagedType.IUnknown), Optional] object pUnkOuter, EMBDHLP flags, [Optional] IClassFactory pCF, in Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object lplpObj);
///
/// Extends OleCreate functionality by supporting more efficient instantiation of objects in containers requiring caching of multiple
/// presentation formats or data, instead of the single format supported by OleCreate.
///
/// Identifies the class of the object to create.
/// Reference to the identifier of the interface of the object to return.
/// This value can be 0 or OLECREATE_LEAVERUNNING (0x00000001).
/// Value taken from the OLERENDER enumeration.
///
/// When is OLERENDER_FORMAT, indicates the number of FORMATETC structures in the rgFormatEtc array,
/// which must be at least one. In all other cases, this parameter must be zero.
///
///
/// When is OLERENDER_FORMAT, points to an array of cFormats DWORD elements, each of which is a
/// combination of values from the ADVF enumeration. Each element of this array is passed in as the
/// parameter to a call to either IOleCache::Cache or IDataObject::DAdvise, depending on whether pAdviseSink is NULL or non-
/// NULL (see below). In all other cases, this parameter must be NULL.
///
///
/// When is OLERENDER_FORMAT, points to an array of cFormats FORMATETC structures. When pAdviseSink is
/// NULL, each element of this array is passed as the pFormatEtc parameter to a call to the object's IOleCache::Cache. This
/// populates the data and presentation cache managed by the objects in-process handler (typically the default handler) with
/// presentation or other cacheable data. When pAdviseSink is non- NULL, each element of this array is passed as the
/// pFormatEtc parameter to a call to IDataObject::DAdvise. This allows the caller (typically an OLE Container) to do its own caching
/// or processing of data received from the object. In all other cases, this parameter must be NULL.
///
///
/// When is OLERENDER_FORMAT, may be either a valid IAdviseSink pointer, indicating custom caching or
/// processing of data advises, or NULL, indicating default caching of data formats. In all other cases, this parameter must
/// be NULL.
///
///
/// Location to return the array of dwConnection values returned when the pAdviseSink interface is registered for each advisory
/// connection using IDataObject::DAdvise, or NULL if the returned advisory connections are not needed. Must be NULL,
/// if pAdviseSink is NULL.
///
///
/// Pointer to the primary interface through which the object will request services from its container. This parameter may be
/// NULL, in which case it is the caller's responsibility to establish the client site as soon as possible using IOleObject::SetClientSite.
///
///
/// Pointer to the storage to use for the object and any default data or presentation caching established for it. This parameter may
/// not be NULL.
///
///
/// Address of output pointer variable that receives the interface pointer requested in . Upon successful
/// return, *ppvObj contains the requested interface pointer on the newly created object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_NOINTERFACE
/// The provided interface identifier is invalid.
///
///
///
///
/// The following call to OleCreate:
/// is equivalent to the following call to OleCreateEx:
///
/// Existing instantiation functions, (OleCreate, OleCreateFromFile, OleCreateFromData, OleCreateLink, OleCreateLinkToFile, and
/// OleCreateLinkFromData) create only a single presentation or data format cache in the default cache location (within the
/// '\001OlePresXXX' streams of the passed-in IStorage), during instantiation. Plus, these caches must be created when the object
/// next enters the running state. Since most applications require caching at least two presentations (screen and printer) and may
/// require caching data in a different format or location from the handler, applications must typically launch and shut down the
/// object server multiple times in order to prime their data caches during object creation, i.e., Insert Object, Insert Object from
/// File, and Paste Object.
///
///
/// Extended versions of these creation functions solve this problem. OleCreateEx, OleCreateFromFileEx, OleCreateFromDataEx,
/// OleCreateLinkEx, OleCreateLinkToFileEx, and OleCreateLinkFromDataEx contain the following new parameters: dwFlags to indicate
/// additional options, cFormats to indicate how many formats to cache, rgAdvf, from the ADVF enumeration, to specify the advise
/// flags for each format to be cached, pAdviseSink to indicate whether presentation (default-handler) or data (non-default-handler)
/// caching is required, rgdwConnection to return IDataObject::DAdvise cookies, and pFormatEtc, an array of formats rather than a
/// single format.
///
///
/// Containers requiring that multiple presentations be cached on their behalf by the object's handler can simply call these
/// functions and specify the number of formats in cFormats, the ADVF flags for each format in rgAdvf, and the set of formats in
/// pFormatEtc. These containers pass NULL for pAdviseSink.
///
///
/// Containers performing all their own data- or presentation-caching perform these same steps, but pass a non- NULL
/// pAdviseSink. They perform their own caching or manipulation of the object or data during IAdviseSink::OnDataChange. Typically
/// such containers never establish the advisory connections with ADVF_NODATA, although they are not prevented from doing so.
///
///
/// These new functions are for OLE Compound Documents. Using these functions, applications can avoid the repeated launching and
/// initialization steps required by the current functions. They are targeted at OLE Compound Document container applications that
/// use default data- and presentation-caching, and also at applications that provide their own caching and data transfer from the
/// underlying IDataObject::DAdvise support.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreateex HRESULT OleCreateEx( IN REFCLSID rclsid, IN REFIID
// riid, IN DWORD dwFlags, IN DWORD renderopt, IN ULONG cFormats, IN DWORD *rgAdvf, IN LPFORMATETC rgFormatEtc, IN IAdviseSink
// *lpAdviseSink, OUT DWORD *rgdwConnection, IN LPOLECLIENTSITE pClientSite, IN LPSTORAGE pStg, OUT LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "11f2703c-b596-4cb9-855a-d8cf4b947fae")]
public static extern HRESULT OleCreateEx(in Guid rclsid, in Guid riid, OLECREATE dwFlags, OLERENDER renderopt, uint cFormats, [In, Optional] ADVF[] rgAdvf, [In, Optional] FORMATETC[] rgFormatEtc,
[Optional] IAdviseSink lpAdviseSink, [Out, Optional] uint[] rgdwConnection, [Optional] IOleClientSite pClientSite, IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
///
/// Creates an embedded object from a data transfer object retrieved either from the clipboard or as part of an OLE drag-and-drop
/// operation. It is intended to be used to implement a paste from an OLE drag-and-drop operation.
///
///
/// Pointer to the IDataObject interface on the data transfer object that holds the data from which the object is created.
///
///
/// Reference to the identifier of the interface the caller later uses to communicate with the new object (usually IID_IOleObject,
/// defined in the OLE headers as the interface identifier for IOleObject).
///
///
/// Value from the enumeration OLERENDER that indicates the locally cached drawing or data-retrieval capabilities the newly created
/// object is to have. Additional considerations are described in the following Remarks section.
///
///
/// Pointer to a value from the enumeration OLERENDER that indicates the locally cached drawing or data-retrieval capabilities the
/// newly created object is to have. The OLERENDER value chosen affects the possible values for the pFormatEtc parameter.
///
///
/// Pointer to an instance of IOleClientSite, the primary interface through which the object will request services from its
/// container. This parameter can be NULL.
///
/// Pointer to the IStorage interface on the storage object. This parameter may not be NULL.
///
/// Address of pointer variable that receives the interface pointer requested in . Upon successful return,
/// *ppvObj contains the requested interface pointer on the newly created object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// OLE_E_STATIC
/// Indicates OLE can create only a static object.
///
/// -
/// DV_E_FORMATETC
/// No acceptable formats are available for object creation.
///
///
///
///
///
/// The OleCreateFromData function creates an embedded object from a data transfer object supporting the IDataObject
/// interface. The data object in this case is either the type retrieved from the clipboard with a call to the OleGetClipboard
/// function or is part of an OLE drag-and-drop operation (the data object is passed to a call to IDropTarget::Drop).
///
///
/// If either the FileName or FileNameW clipboard format (CF_FILENAME) is present in the data transfer object, and CF_EMBEDDEDOBJECT
/// or CF_EMBEDSOURCE do not exist, OleCreateFromData first attempts to create a package containing the indicated file.
/// Generally, it takes the first available format.
///
///
/// If OleCreateFromData cannot create a package, it tries to create an object using the CF_EMBEDDEDOBJECT format. If that
/// format is not available, OleCreateFromData tries to create it with the CF_EMBEDSOURCE format. If neither of these formats
/// is available and the data transfer object supports the IPersistStorage interface, OleCreateFromData calls the object's
/// IPersistStorage::Save to have the object save itself.
///
///
/// If an existing linked object is selected, then copied, it appears on the clipboard as just another embeddable object.
/// Consequently, a paste operation that invokes OleCreateFromData may create a linked object. After the paste operation, the
/// container should call the QueryInterface function, requesting IID_IOleLink (defined in the OLE headers as the interface
/// identifier for IOleLink), to determine if a linked object was created.
///
///
/// Use the and pFormatetc parameters to control the caching capability of the newly created object. For
/// general information about using the interaction of these parameters to determine what is to be cached, refer to the OLERENDER
/// enumeration. There are, however, some additional specific effects of these parameters on the way OleCreateFromData
/// initializes the cache.
///
///
/// When OleCreateFromData uses either the CF_EMBEDDEDOBJECT or the CF_EMBEDSOURCE clipboard format to create the embedded
/// object, the main difference between the two is where the cache-initialization data is stored:
///
///
/// -
///
/// CF_EMBEDDEDOBJECT indicates that the source is an existing embedded object. It already has in its cache the appropriate data, and
/// OLE uses this data to initialize the cache of the new object.
///
///
/// -
///
/// CF_EMBEDSOURCE indicates that the source data object contains the cache-initialization information in formats other than
/// CF_EMBEDSOURCE. OleCreateFromData uses these to initialize the cache of the newly embedded object.
///
///
///
/// The values affect cache initialization as follows.
///
///
/// Value
/// Description
///
/// -
/// OLERENDER_DRAW & OLERENDER_FORMAT
///
/// If the presentation information to be cached is currently present in the appropriate cache-initialization pool, it is used.
/// (Appropriate locations are in the source data object cache for CF_EMBEDDEDOBJECT, and in the other formats in the source data
/// object for CF_EMBEDSOURCE.) If the information is not present, the cache is initially empty, but will be filled the first time
/// the object is run. No other formats are cached in the newly created object.
///
///
/// -
/// OLERENDER_NONE
///
/// Nothing is to be cached in the newly created object. If the source has the CF_EMBEDDEDOBJECT format, any existing cached data
/// that has been copied is removed.
///
///
/// -
/// OLERENDER_ASIS
///
/// If the source has the CF_EMBEDDEDOBJECT format, the cache of the new object is to contain the same cache data as the source
/// object. For CF_EMBEDSOURCE, nothing is to be cached in the newly created object. This option should be used by more sophisticated
/// containers. After this call, such containers would call IOleCache::Cache and IOleCache::Uncache to set up exactly what is to be
/// cached. For CF_EMBEDSOURCE, they would then also call IOleCache::InitCache.
///
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreatefromdata HRESULT OleCreateFromData( IN LPDATAOBJECT
// pSrcDataObj, IN REFIID riid, IN DWORD renderopt, IN LPFORMATETC pFormatEtc, IN LPOLECLIENTSITE pClientSite, IN LPSTORAGE pStg, OUT
// LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "aa5e997e-60d4-472d-9c81-5359c277bde3")]
public static extern HRESULT OleCreateFromData(IDataObject pSrcDataObj, in Guid riid, OLERENDER renderopt, in FORMATETC pFormatEtc, [Optional] IOleClientSite pClientSite, IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
///
/// Extends OleCreateFromData functionality by supporting more efficient instantiation of objects in containers requiring caching of
/// multiple formats of presentation or data, instead of the single format supported by OleCreateFromData.
///
/// Pointer to the data transfer object holding the new data used to create the new object. (see OleCreateFromData).
/// Reference to the identifier of the interface of the object to return.
/// This parameter can be 0 or OLECREATE_LEAVERUNNING (0x00000001).
/// Value taken from the OLERENDER enumeration.
///
/// When is OLERENDER_FORMAT, indicates the number of FORMATETC structures in the rgFormatEtc array,
/// which must be at least one. In all other cases, this parameter must be zero.
///
///
/// When is OLERENDER_FORMAT, points to an array of DWORD elements, each of which is a
/// combination of values from the ADVF enumeration. Each element of this array is passed in as the
/// parameter to a call to either IOleCache::Cache or IDataObject::DAdvise, depending on whether pAdviseSink is NULL or non-
/// NULL (see below). In all other cases, this parameter must be NULL.
///
///
/// When is OLERENDER_FORMAT, points to an array of FORMATETC structures. When pAdviseSink is
/// NULL, each element of this array is passed as the pFormatEtc parameter to a call to the object's IOleCache::Cache. This
/// populates the data and presentation cache managed by the object's in-process handler (typically the default handler) with
/// presentation or other cacheable data. When pAdviseSink is non- NULL, each element of this array is passed as the
/// pFormatEtc parameter to a call to IDataObject::DAdvise. This allows the caller (typically an OLE Container) to do its own caching
/// or processing of data received from the object.
///
///
/// When is OLERENDER_FORMAT, may be either a valid IAdviseSink pointer, indicating custom caching or
/// processing of data advises, or NULL, indicating default caching of data formats.
///
///
/// Location to return the array of dwConnection values returned when the IAdviseSink interface is registered for each advisory
/// connection using IDataObject::DAdvise, or NULL if the returned advisory connections are not needed. This parameter must be
/// NULL if pAdviseSink is NULL.
///
///
/// Pointer to the primary interface through which the object will request services from its container. This parameter may be
/// NULL, in which case it is the caller's responsibility to establish the client site as soon as possible using IOleObject::SetClientSite.
///
///
/// Pointer to the storage to use for the object and any default data or presentation caching established for it.
///
///
/// Address of output pointer variable that receives the interface pointer requested in . Upon successful
/// return, *ppvObj contains the requested interface pointer on the newly created object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_NOINTERFACE
/// The provided interface identifier is invalid.
///
/// -
/// E_INVALIDARG
/// One or more parameters are invalid.
///
///
///
///
/// The following call to OleCreateFromData:
/// is equivalent to the following call to OleCreateFromDataEx:
///
/// Existing instantiation functions (OleCreate, OleCreateFromFile, OleCreateFromData, OleCreateLink, OleCreateLinkToFile, and
/// OleCreateLinkFromData) create only a single presentation or data format cache in the default cache location (within the
/// '\001OlePresXXX' streams of the passed-in IStorage) during instantiation. Plus, these caches must be created when the object next
/// enters the running state. Because most applications require caching at least two presentations (screen and printer) and may
/// require caching data in a different format or location from the handler, applications must typically launch and shut down the
/// object server multiple times in order to prime their data caches during object creation, i.e., Insert Object, Insert Object from
/// File, and Paste Object.
///
///
/// Extended versions of these creation functions solve this problem. OleCreateEx, OleCreateFromFileEx, OleCreateFromDataEx,
/// OleCreateLinkEx, OleCreateLinkToFileEx, and OleCreateLinkFromDataEx, contain the following new parameters: dwFlags to indicate
/// additional options, cFormats to indicate how many formats to cache, rgAdvf, from the ADVF enumeration, to specify the advise
/// flags for each format to be cached, pAdviseSink to indicate whether presentation (default-handler) or data (non-default-handler)
/// caching is required, rgdwConnection to return IDataObject::DAdvise cookies, and rgFormatEtc, an array of formats rather than a
/// single format.
///
///
/// Containers requiring that multiple presentations be cached on their behalf by the object's handler can simply call these
/// functions and specify the number of formats in cFormats, the ADVF flags for each format in rgAdvf, and the set of formats in
/// rgFormatEtc. These containers pass NULL for pAdviseSink.
///
///
/// Containers performing all their own data- or presentation-caching perform these same steps, but pass a non- NULL
/// pAdviseSink. They perform their own caching or manipulation of the object or data during IAdviseSink::OnDataChange. Typically,
/// such containers never establish the advisory connections with ADVF_NODATA, although they are not prevented from doing so.
///
///
/// These new functions are for OLE Compound Documents. Using these functions, applications can avoid the repeated launching and
/// initialization steps required by the current functions. They are targeted at OLE Compound Document container applications that
/// use default data- and presentation-caching, and also at applications that provide their own caching and data transfer from the
/// underlying IDataObject::DAdvise support.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreatefromdataex HRESULT OleCreateFromDataEx( IN LPDATAOBJECT
// pSrcDataObj, IN REFIID riid, IN DWORD dwFlags, IN DWORD renderopt, IN ULONG cFormats, IN DWORD *rgAdvf, IN LPFORMATETC
// rgFormatEtc, IN IAdviseSink *lpAdviseSink, OUT DWORD *rgdwConnection, IN LPOLECLIENTSITE pClientSite, IN LPSTORAGE pStg, OUT
// LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "10091a24-6a50-4eb2-a518-b92a572daa6c")]
public static extern HRESULT OleCreateFromDataEx(IDataObject pSrcDataObj, in Guid riid, OLECREATE dwFlags, OLERENDER renderopt, uint cFormats, [In, Optional] ADVF[] rgAdvf, [In, Optional] FORMATETC[] rgFormatEtc,
[Optional] IAdviseSink lpAdviseSink, [Out, Optional] uint[] rgdwConnection, [Optional] IOleClientSite pClientSite, IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
/// Creates an embedded object from the contents of a named file.
/// This parameter is reserved and must be CLSID_NULL.
/// Pointer to the name of the file from which the new object should be initialized.
/// Reference to the identifier of the interface of the object to return.
/// Value taken from the OLERENDER enumeration.
///
/// Depending on which OLERENDER flag is used as the value of , this is a pointer to an FORMATETC
/// enumeration value. For restrictions, see the OLERENDER enumeration.
/// This parameter, along with the parameter, specifies what the new object can cache initially.
///
///
/// Pointer to the primary interface through which the object will request services from its container. This parameter may be
/// NULL, in which case it is the caller's responsibility to establish the client site as soon as possible using IOleObject::SetClientSite.
///
///
/// Pointer to the storage to use for the object and any default data or presentation caching established for it.
///
///
/// Address of output pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvObj
/// contains the requested interface pointer on the newly created object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// STG_E_FILENOTFOUND
/// File not bound.
///
/// -
/// OLE_E_CANT_BINDTOSOURCE
/// Not able to bind to source.
///
/// -
/// STG_E_MEDIUMFULL
/// The medium is full.
///
/// -
/// DV_E_TYMED
/// Invalid TYMED.
///
/// -
/// DV_E_LINDEX
/// Invalid LINDEX.
///
/// -
/// DV_E_FORMATETC
/// Invalid FORMATETC structure.
///
///
///
///
///
/// The OleCreateFromFile function creates a new embedded object from the contents of a named file. If the ProgID in the
/// registration database contains the PackageOnFileDrop key, it creates a package. If not, the function calls the GetClassFile
/// function to get the CLSID associated with the lpszFileName parameter, and then creates an OLE 2-embedded object associated with
/// that CLSID. The rclsid parameter of OleCreateFromFile will always be ignored, and should be set to CLSID_NULL.
///
///
/// As for other OleCreateXxx functions, the newly created object is not shown to the user for editing, which requires a DoVerb
/// operation. It is used to implement insert file operations.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreatefromfile HRESULT OleCreateFromFile( IN REFCLSID rclsid,
// IN LPCOLESTR lpszFileName, IN REFIID riid, IN DWORD renderopt, IN LPFORMATETC lpFormatEtc, IN LPOLECLIENTSITE pClientSite, IN
// LPSTORAGE pStg, OUT LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "98c63646-6617-46b6-8c3e-82d1c4d0adb6")]
public static extern HRESULT OleCreateFromFile(in Guid rclsid, [MarshalAs(UnmanagedType.LPWStr)] string lpszFileName, in Guid riid, OLERENDER renderopt, in FORMATETC lpFormatEtc, [Optional] IOleClientSite pClientSite, IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
///
/// Extends OleCreateFromFile functionality by supporting more efficient instantiation of objects in containers requiring caching of
/// multiple presentation formats or data, instead of the single format supported by OleCreateFromFile.
///
/// This parameter is reserved and must be CLSID_NULL.
/// Pointer to the name of the file from which the new object should be initialized.
/// Reference to the identifier of the interface of the object to return.
/// This parameter can be 0 or OLECREATE_LEAVERUNNING (0x00000001).
/// Value taken from the OLERENDER enumeration.
///
/// When renderopt is OLERENDER_FORMAT, indicates the number of FORMATETC structures in the rgFormatEtc array, which must be at least
/// one. In all other cases, this parameter must be zero.
///
///
/// When renderopt is OLERENDER_FORMAT, points to an array of DWORD elements, each of which is a combination of values from
/// the ADVF enumeration. Each element of this array is passed in as the advf parameter to a call to either IOleCache::Cache or
/// IDataObject::DAdvise, depending on whether pAdviseSink is NULL or non- NULL (see below). In all other cases, this
/// parameter must be NULL.
///
///
/// When renderopt is OLERENDER_FORMAT, points to an array of FORMATETC structures. When pAdviseSink is NULL, each element of
/// this array is passed as the pFormatEtc parameter to a call to the object's IOleCache::Cache. This populates the data and
/// presentation cache managed by the objects in-process handler (typically the default handler) with presentation or other cacheable
/// data. When pAdviseSink is non- NULL, each element of this array is passed as the pFormatEtc parameter to a call to
/// IDataObject::DAdvise. This allows the caller (typically an OLE Container) to do its own caching or processing of data received
/// from the object.
///
///
/// When renderopt is OLERENDER_FORMAT, may be either a valid IAdviseSink pointer, indicating custom caching or processing of data
/// advises, or NULL, indicating default caching of data formats.
///
///
/// Location to return the array of dwConnection values returned when the pAdviseSink interface is registered for each advisory
/// connection using IDataObject::DAdvise, or NULL if the returned advisory connections are not needed. This parameter must be
/// NULL if pAdviseSink is NULL.
///
///
/// Pointer to the primary interface through which the object will request services from its container. This parameter may be
/// NULL, in which case it is the caller's responsibility to establish the client site as soon as possible using IOleObject::SetClientSite.
///
///
/// Pointer to the storage to use for the object and any default data or presentation caching established for it.
///
///
/// Address of output pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvObj
/// contains the requested interface pointer on the newly created object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_NOINTERFACE
/// The provided interface identifier is invalid.
///
/// -
/// E_INVALIDARG
/// One or more parameters are invalid.
///
///
///
///
/// The following call to OleCreateFromFile:
/// is equivalent to the following call to OleCreateFromFileEx:
///
/// Existing instantiation functions (OleCreate, OleCreateFromFile, OleCreateFromData, OleCreateLink, OleCreateLinkToFile, and
/// OleCreateLinkFromData) create only a single presentation or data format cache in the default cache location (within the
/// '\001OlePresXXX' streams of the passed-in IStorage), during instantiation. Plus, these caches must be created when the object
/// next enters the running state. Because most applications require caching at least two presentations (screen and printer) and may
/// require caching data in a different format or location from the handler, applications must typically launch and shut down the
/// object server multiple times in order to prime their data caches during object creation, i.e., Insert Object, Insert Object from
/// File, and Paste Object.
///
///
/// Extended versions of these creation functions solve this problem. OleCreateEx, OleCreateFromFileEx, OleCreateFromDataEx,
/// OleCreateLinkEx, OleCreateLinkToFileEx, and OleCreateLinkFromDataEx, contain the following new parameters: dwFlags to indicate
/// additional options, cFormats to indicate how many formats to cache, rgAdvf, from the ADVF enumeration, to specify the advise
/// flags for each format to be cached, pAdviseSink to indicate whether presentation (default-handler) or data (non-default-handler)
/// caching is required, rgdwConnection to return IDataObject::DAdvise cookies, and rgFormatEtc, an array of formats rather than a
/// single format.
///
///
/// Containers requiring that multiple presentations be cached on their behalf by the object's handler can simply call these
/// functions and specify the number of formats in cFormats, the ADVF flags for each format in rgAdvf, and the set of formats in
/// rgFormatEtc. These containers pass NULL for pAdviseSink.
///
///
/// Containers performing all their own data- or presentation-caching perform these same steps, but pass a non- NULL
/// pAdviseSink. They perform their own caching or manipulation of the object or data during IAdviseSink::OnDataChange. Typically,
/// such containers never establish the advisory connections with ADVF_NODATA, although they are not prevented from doing so.
///
///
/// These new functions are for OLE Compound Documents. Using these functions, applications can avoid the repeated launching and
/// initialization steps required by the current functions. They are targeted at OLE Compound Document container applications that
/// use default data- and presentation-caching, and also at applications that provide their own caching and data transfer from the
/// underlying IDataObject::DAdvise support.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreatefromfileex HRESULT OleCreateFromFileEx( IN REFCLSID
// rclsid, IN LPCOLESTR lpszFileName, IN REFIID riid, IN DWORD dwFlags, IN DWORD renderopt, IN ULONG cFormats, IN DWORD *rgAdvf, IN
// LPFORMATETC rgFormatEtc, IN IAdviseSink *lpAdviseSink, OUT DWORD *rgdwConnection, IN LPOLECLIENTSITE pClientSite, IN LPSTORAGE
// pStg, OUT LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "a75bb031-6e4a-4440-82f3-6a6f9417c62b")]
public static extern HRESULT OleCreateFromFileEx(in Guid rclsid, [MarshalAs(UnmanagedType.LPWStr)] string lpszFileName, in Guid riid, OLECREATE dwFlags, OLERENDER renderopt, uint cFormats, [In, Optional] ADVF[] rgAdvf, [In, Optional] FORMATETC[] rgFormatEtc,
[Optional] IAdviseSink lpAdviseSink, [Out, Optional] uint[] rgdwConnection, [Optional] IOleClientSite pClientSite, IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
/// Creates an OLE compound-document linked object.
///
/// Pointer to the IMoniker interface on the moniker that can be used to locate the source of the linked object.
///
///
/// Reference to the identifier of the interface the caller later uses to communicate with the new object (usually IID_IOleObject,
/// defined in the OLE headers as the interface identifier for IOleObject).
///
///
/// Specifies a value from the enumeration OLERENDER that indicates the locally cached drawing or data-retrieval capabilities the
/// newly created object is to have. Additional considerations are described in the Remarks section below.
///
///
/// Pointer to a value from the enumeration OLERENDER that indicates the locally cached drawing or data-retrieval capabilities the
/// newly created object is to have. The OLERENDER value chosen affects the possible values for the lpFormatEtc parameter.
///
///
/// Pointer to an instance of IOleClientSite, the primary interface through which the object will request services from its
/// container. This parameter can be NULL.
///
/// Pointer to the IStorage interface on the storage object. This parameter cannot be NULL.
///
/// Address of pointer variable that receives the interface pointer requested in . Upon successful return,
/// *ppvObj contains the requested interface pointer on the newly created object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// OLE_E_CANT_BINDTOSOURCE
/// Not able to bind to source.
///
///
///
/// Call OleCreateLink to allow a container to create a link to an object.
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreatelink HRESULT OleCreateLink( IN LPMONIKER pmkLinkSrc, IN
// REFIID riid, IN DWORD renderopt, IN LPFORMATETC lpFormatEtc, IN LPOLECLIENTSITE pClientSite, IN LPSTORAGE pStg, OUT LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "ef52dc37-aa63-47f3-a04f-f9d22178690f")]
public static extern HRESULT OleCreateLink(IMoniker pmkLinkSrc, in Guid riid, OLERENDER renderopt, in FORMATETC lpFormatEtc, [Optional] IOleClientSite pClientSite, IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
///
/// Extends OleCreateLink functionality by supporting more efficient instantiation of objects in containers requiring caching
/// of multiple formats of presentations or data, instead of the single format supported by OleCreateLink.
///
/// Pointer to a moniker to the object to create a link to.
/// Reference to the identifier of the interface of the object to return.
/// This parameter can be 0 or OLECREATE_LEAVERUNNING (0x00000001).
/// Value taken from the OLERENDER enumeration.
///
/// When renderopt is OLERENDER_FORMAT, indicates the number of FORMATETC structures in the rgFormatEtc array, which must be at least
/// one. In all other cases, this parameter must be zero.
///
///
/// When renderopt is OLERENDER_FORMAT, points to an array of DWORD elements, each of which is a combination of values from
/// the ADVF enumeration. Each element of this array is passed in as the advf parameter to a call to either IOleCache::Cache or
/// IDataObject::DAdvise, depending on whether pAdviseSink is NULL or non- NULL (see below). In all other cases, this
/// parameter must be NULL.
///
///
/// When renderopt is OLERENDER_FORMAT, points to an array of FORMATETC structures. When pAdviseSink is NULL, each element of
/// this array is passed as the pFormatEtc parameter to a call to the object's IOleCache::Cache. This populates the data and
/// presentation cache managed by the objects in-process handler (typically the default handler) with presentation or other cacheable
/// data. When pAdviseSink is non- NULL, each element of this array is passed as the pFormatEtc parameter to a call to
/// IDataObject::DAdvise. This allows the caller (typically an OLE Container) to do its own caching or processing of data received
/// from the object.
///
///
/// When renderopt is OLERENDER_FORMAT, may be either a valid IAdviseSink pointer, indicating custom caching or processing of data
/// advises, or NULL, indicating default caching of data formats.
///
///
/// Location to return the array of dwConnection values returned when the IAdviseSink interface is registered for each advisory
/// connection using IDataObject::DAdvise, or NULL if the returned advisory connections are not needed. This parameter must be
/// NULL if pAdviseSink is NULL.
///
///
/// Pointer to the primary interface through which the object will request services from its container. This parameter can be
/// NULL, in which case it is the caller's responsibility to establish the client site as soon as possible using IOleObject::SetClientSite.
///
///
/// Pointer to the storage to use for the object and any default data or presentation caching established for it.
///
///
/// Address of output pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvObj
/// contains the requested interface pointer on the newly created object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_NOINTERFACE
/// The provided interface identifier is invalid.
///
/// -
/// E_INVALIDARG
/// One or more parameters are invalid.
///
///
///
///
/// The following call to OleCreateLink:
/// is equivalent to the following call to OleCreateLinkEx:
///
/// Existing instantiation functions (OleCreate, OleCreateFromFile, OleCreateFromData, OleCreateLink, OleCreateLinkToFile, and
/// OleCreateLinkFromData) create only a single presentation or data format cache in the default cache location (within the
/// '\001OlePresXXX' streams of the passed-in IStorage) during instantiation. Plus, these caches must be created when the object next
/// enters the running state. Because most applications require caching in at least two presentations (screen and printer) and may
/// require caching data in a different format or location from the handler, applications must typically launch and shut down the
/// object server multiple times in order to prime their data caches during object creation, i.e., Insert Object, Insert Object from
/// File, and Paste Object.
///
///
/// Extended versions of these creation functions solve this problem. OleCreateEx, OleCreateFromFileEx, OleCreateFromDataEx,
/// OleCreateLinkEx, OleCreateLinkToFileEx, and OleCreateLinkFromDataEx, contain the following new parameters: dwFlags to
/// indicate additional options, cFormats to indicate how many formats to cache, rgAdvf, from the ADVF enumeration, to specify the
/// advise flags for each format to be cached, pAdviseSink to indicate whether presentation (default-handler) or data
/// (non-default-handler) caching is required, rgdwConnection to return IDataObject::DAdvise cookies, and rgFormatEtc, an array of
/// formats rather than a single format.
///
///
/// Containers requiring that multiple presentations be cached on their behalf by the object's handler can simply call these
/// functions and specify the number of formats in cFormats, the ADVF flags for each format in rgAdvf, and the set of formats in
/// rgFormatEtc. These containers pass NULL for pAdviseSink.
///
///
/// Containers performing all their own data- or presentation-caching perform these same steps, but pass a non- NULL
/// pAdviseSink. They perform their own caching or manipulation of the object or data during IAdviseSink::OnDataChange. Typically,
/// such containers never establish the advisory connections with ADVF_NODATA, although they are not prevented from doing so.
///
///
/// These new functions are for OLE Compound Documents. Using these functions, applications can avoid the repeated launching and
/// initialization steps required by the current functions. They are targeted at OLE Compound Document container applications that
/// use default data- and presentation-caching, and also at applications that provide their own caching and data transfer from the
/// underlying IDataObject::DAdvise support.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreatelinkex HRESULT OleCreateLinkEx( IN LPMONIKER pmkLinkSrc,
// IN REFIID riid, IN DWORD dwFlags, IN DWORD renderopt, IN ULONG cFormats, IN DWORD *rgAdvf, IN LPFORMATETC rgFormatEtc, IN
// IAdviseSink *lpAdviseSink, OUT DWORD *rgdwConnection, IN LPOLECLIENTSITE pClientSite, IN LPSTORAGE pStg, OUT LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "b43acd14-3cf8-45da-8c2c-f2f6dc2ada78")]
public static extern HRESULT OleCreateLinkEx(IMoniker pmkLinkSrc, in Guid riid, OLECREATE dwFlags, OLERENDER renderopt, uint cFormats, [In, Optional] ADVF[] rgAdvf, [In, Optional] FORMATETC[] rgFormatEtc,
[Optional] IAdviseSink lpAdviseSink, [Out, Optional] uint[] rgdwConnection, [Optional] IOleClientSite pClientSite, IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
///
/// Creates a linked object from a data transfer object retrieved either from the clipboard or as part of an OLE drag-and-drop operation.
///
///
/// Pointer to the IDataObject interface on the data transfer object from which the linked object is to be created.
///
///
/// Reference to the identifier of interface the caller later uses to communicate with the new object (usually IID_IOleObject,
/// defined in the OLE headers as the interface identifier for IOleObject).
///
///
/// Value from the enumeration OLERENDER that indicates the locally cached drawing or data-retrieval capabilities the newly created
/// object is to have. Additional considerations are described in the following Remarks section.
///
///
/// Pointer to a value from the enumeration OLERENDER that indicates the locally cached drawing or data-retrieval capabilities the
/// newly created object is to have. The OLERENDER value chosen affects the possible values for the pFormatEtc parameter.
///
///
/// Pointer to an instance of IOleClientSite, the primary interface through which the object will request services from its
/// container. This parameter can be NULL.
///
/// Pointer to the IStorage interface on the storage object. This parameter cannot be NULL.
///
/// Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, ppvObj contains the
/// requested interface pointer on the newly created object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// CLIPBRD_E_CANT_OPEN
/// Not able to open the clipboard.
///
/// -
/// OLE_E_CANT_GETMONIKER
/// Not able to extract the object's moniker.
///
/// -
/// OLE_E_CANT_BINDTOSOURCE
/// Not able to bind to source. Binding is necessary to get the cache's initialization data.
///
///
///
///
///
/// The OleCreateLinkFromData function is used to implement either a paste-link or a drag-link operation. Its operation is
/// similar to that of the OleCreateFromData function, except that it creates a link, and looks for different data formats. If the
/// CF_LINKSOURCE format is not present, and either the FileName or FileNameW clipboard format is present in the data transfer
/// object, OleCreateLinkFromData creates a package containing the link to the indicated file.
///
///
/// You use the renderopt and pFormatetc parameters to control the caching capability of the newly created object. For general
/// information on how to determine what is to be cached, refer to the OLERENDER enumeration for a description of the interaction
/// between renderopt and pFormatetc. There are, however, some additional specific effects of these parameters on the way
/// OleCreateLinkFromData initializes the cache, as follows.
///
///
///
/// Value
/// Description
///
/// -
/// OLERENDER_DRAW, OLERENDER_FORMAT
///
/// If the presentation information is in the other formats in the source data object, this information is used. If the information
/// is not present, the cache is initially empty, but will be filled the first time the object is run. No other formats are cached in
/// the newly created object.
///
///
/// -
/// OLERENDER_NONE, OLERENDER_ASIS
/// Nothing is to be cached in the newly created object.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreatelinkfromdata HRESULT OleCreateLinkFromData( IN
// LPDATAOBJECT pSrcDataObj, IN REFIID riid, IN DWORD renderopt, IN LPFORMATETC pFormatEtc, IN LPOLECLIENTSITE pClientSite, IN
// LPSTORAGE pStg, OUT LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "3eda0cf5-c33d-43cf-ba8a-02a4f6383adc")]
public static extern HRESULT OleCreateLinkFromData(IDataObject pSrcDataObj, in Guid riid, OLERENDER renderopt, in FORMATETC pFormatEtc, [Optional] IOleClientSite pClientSite, IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
///
/// Extends OleCreateLinkFromData functionality by supporting more efficient instantiation of objects in containers requiring caching
/// of multiple formats of presentations or data, instead of the single format supported by OleCreateLinkFromData.
///
/// Pointer to the data object to create a link object from.
/// Reference to the identifier of the interface of the object to return.
/// This parameter can be 0 or OLECREATE_LEAVERUNNING (0x00000001).
/// Value taken from the OLERENDER enumeration.
///
/// When renderopt is OLERENDER_FORMAT, indicates the number of FORMATETC structures in the rgFormatEtc array, which must be at least
/// one. In all other cases, this parameter must be zero.
///
///
/// When renderopt is OLERENDER_FORMAT, points to an array of DWORD elements, each of which is a combination of values from
/// the ADVF enumeration. Each element of this array is passed in as the advf parameter to a call to either IOleCache::Cache or
/// IDataObject::DAdvise, depending on whether pAdviseSink is NULL or non- NULL (see below). In all other cases, this
/// parameter must be NULL.
///
///
/// When renderopt is OLERENDER_FORMAT, points to an array of FORMATETC structures. When pAdviseSink is NULL, each element of
/// this array is passed as the pFormatEtc parameter to a call to the object's IOleCache::Cache. This populates the data and
/// presentation cache managed by the objects in-process handler (typically the default handler) with presentation or other cacheable
/// data. When pAdviseSink is non- NULL, each element of this array is passed as the pFormatEtc parameter to a call to
/// IDataObject::DAdvise. This allows the caller (typically an OLE Container) to do its own caching or processing of data received
/// from the object.
///
///
/// When renderopt is OLERENDER_FORMAT, may be either a valid IAdviseSink pointer, indicating custom caching or processing of data
/// advises, or NULL, indicating default caching of data formats.
///
///
/// Location to return the array of dwConnection values returned when the pAdviseSink interface is registered for each advisory
/// connection using IDataObject::DAdvise, or NULL if the returned advisory connections are not needed. This parameter must be
/// NULL if pAdviseSink is NULL.
///
///
/// Pointer to the primary interface through which the object will request services from its container. This parameter can be
/// NULL, in which case it is the caller's responsibility to establish the client site as soon as possible using IOleObject::SetClientSite.
///
///
/// Pointer to the storage to use for the object and any default data or presentation caching established for it.
///
///
/// Address of output pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvObj
/// contains the requested interface pointer on the newly created object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_NOINTERFACE
/// The provided interface identifier is invalid.
///
/// -
/// E_INVALIDARG
/// One or more parameters are invalid.
///
///
///
///
/// The following call to OleCreateLinkFromData:
/// is equivalent to the following call to OleCreateLinkFromDataEx:
///
/// Existing instantiation functions (OleCreate, OleCreateFromFile, OleCreateFromData, OleCreateLink, OleCreateLinkToFile, and
/// OleCreateLinkFromData), create only a single presentation or data format cache in the default cache location (within the
/// '\001OlePresXXX' streams of the passed-in IStorage) during instantiation. Plus, these caches must be created when the object next
/// enters the running state. Because most applications require caching at least two presentations (screen and printer) and may
/// require caching data in a different format or location from the handler, applications must typically launch and shut down the
/// object server multiple times in order to prime their data caches during object creation, i.e., Insert Object, Insert Object from
/// File, and Paste Object.
///
///
/// Extended versions of these creation functions solve this problem. OleCreateEx, OleCreateFromFileEx, OleCreateFromDataEx,
/// OleCreateLinkEx, OleCreateLinkToFileEx, and OleCreateLinkFromDataEx, contain the following new parameters: dwFlags to
/// indicate additional options, cFormats to indicate how many formats to cache, rgAdvf, from the ADVF enumeration, to specify the
/// advise flags for each format to be cached, pAdviseSink to indicate whether presentation (default-handler) or data
/// (non-default-handler) caching is required, rgdwConnection to return IDataObject::DAdvise cookies, and rgFormatEtc, an array of
/// formats rather than a single format.
///
///
/// Containers requiring that multiple presentations be cached on their behalf by the object's handler can simply call these
/// functions and specify the number of formats in cFormats, the ADVF flags for each format in rgAdvf, and the set of formats in
/// rgFormatEtc. These containers pass NULL for pAdviseSink.
///
///
/// Containers performing all their own data- or presentation-caching perform these same steps, but pass a non- NULL
/// pAdviseSink. They perform their own caching or manipulation of the object or data during IAdviseSink::OnDataChange. Typically
/// such containers never establish the advisory connections with ADVF_NODATA, although they are not prevented from doing so.
///
///
/// These new functions are for OLE Compound Documents. Using these functions, applications can avoid the repeated launching and
/// initialization steps required by the current functions. They are targeted at OLE Compound Document container applications that
/// use default data- and presentation-caching, and also at applications that provide their own caching and data transfer from the
/// underlying IDataObject::DAdvise support.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreatelinkfromdataex HRESULT OleCreateLinkFromDataEx( IN
// LPDATAOBJECT pSrcDataObj, IN REFIID riid, IN DWORD dwFlags, IN DWORD renderopt, IN ULONG cFormats, IN DWORD *rgAdvf, IN
// LPFORMATETC rgFormatEtc, IN IAdviseSink *lpAdviseSink, OUT IN DWORD *rgdwConnection, IN LPOLECLIENTSITE pClientSite, IN LPSTORAGE
// pStg, OUT LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "f486dc73-3cb9-4839-931a-91cc3a5837d3")]
public static extern HRESULT OleCreateLinkFromDataEx(IDataObject pSrcDataObj, in Guid riid, OLECREATE dwFlags, OLERENDER renderopt, uint cFormats, [In, Optional] ADVF[] rgAdvf, [In, Optional] FORMATETC[] rgFormatEtc,
[Optional] IAdviseSink lpAdviseSink, [Out, Optional] uint[] rgdwConnection, [Optional] IOleClientSite pClientSite, IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
/// Creates an object that is linked to a file.
/// Pointer to a string naming the source file to be linked to.
///
/// Reference to the identifier of the interface the caller later uses to communicate with the new object (usually IID_IOleObject,
/// defined in the OLE headers as the interface identifier for IOleObject).
///
///
/// Value from the enumeration OLERENDER that indicates the locally cached drawing or data-retrieval capabilities the newly created
/// object is to have. Additional considerations are described in the following Remarks section.
///
///
/// Pointer to a value from the enumeration OLERENDER that indicates the locally cached drawing or data-retrieval capabilities the
/// newly created object is to have. The OLERENDER value chosen affects the possible values for the pFormatEtc parameter.
///
///
/// Pointer to an instance of IOleClientSite, the primary interface through which the object will request services from its
/// container. This parameter can be NULL.
///
/// Pointer to the IStorage interface on the storage object. This parameter cannot be NULL.
///
/// Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvObj contains the
/// requested interface pointer on the newly created object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// STG_E_FILENOTFOUND
/// The file name is invalid.
///
/// -
/// OLE_E_CANT_BINDTOSOURCE
/// Not able to bind to source.
///
///
///
///
/// The OleCreateLinkToFile function differs from the OleCreateLink function because it can create links both to files that
/// are not aware of OLE, as well as to those that are using the Windows Packager.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreatelinktofile HRESULT OleCreateLinkToFile( IN LPCOLESTR
// lpszFileName, IN REFIID riid, IN DWORD renderopt, IN LPFORMATETC lpFormatEtc, IN LPOLECLIENTSITE pClientSite, IN LPSTORAGE pStg,
// OUT LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "06b013db-0554-4dbc-b19d-28314fb4fee0")]
public static extern HRESULT OleCreateLinkToFile([MarshalAs(UnmanagedType.LPWStr)] string lpszFileName, in Guid riid, OLERENDER renderopt, in FORMATETC lpFormatEtc, [Optional] IOleClientSite pClientSite, IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
///
/// Extends OleCreateLinkToFile functionality by supporting more efficient instantiation of objects in containers requiring caching
/// of multiple formats of presentations or data, instead of the single format supported by OleCreateLinkToFile.
///
/// Pointer to the name of the file to create a link to.
/// Reference to the identifier of the interface of the object to return.
/// This parameter can be 0 or OLECREATE_LEAVERUNNING (0x00000001).
/// Value taken from the OLERENDER enumeration.
///
/// When renderopt is OLERENDER_FORMAT, indicates the number of FORMATETC structures in the rgFormatEtc array, which must be at least
/// one. In all other cases, this parameter must be zero.
///
///
/// When renderopt is OLERENDER_FORMAT, points to an array of DWORD elements, each of which is a combination of values from
/// the ADVF enumeration. Each element of this array is passed in as the advf parameter to a call to either IOleCache::Cache or
/// IDataObject::DAdvise, depending on whether pAdviseSink is NULL or non- NULL (see below). In all other cases, this
/// parameter must be NULL.
///
///
/// When renderopt is OLERENDER_FORMAT, points to an array of FORMATETC structures. When pAdviseSink is NULL, each element of
/// this array is passed as the pFormatEtc parameter to a call to the object's IOleCache::Cache. This populates the data and
/// presentation cache managed by the objects in-process handler (typically the default handler) with presentation or other cacheable
/// data. When pAdviseSink is non- NULL, each element of this array is passed as the pFormatEtc parameter to a call to
/// IDataObject::DAdvise. This allows the caller (typically an OLE Container) to do its own caching or processing of data received
/// from the object.
///
///
/// When renderopt is OLERENDER_FORMAT, may be either a valid IAdviseSink pointer, indicating custom caching or processing of data
/// advises, or NULL, indicating default caching of data formats.
///
///
/// Location to return the array of dwConnection values returned when the IAdviseSink interface is registered for each advisory
/// connection using IDataObject::DAdvise, or NULL if the returned advisory connections are not needed. This parameter must be
/// NULL if pAdviseSink is NULL.
///
///
/// Pointer to the primary interface through which the object will request services from its container. This parameter may be
/// NULL, in which case it is the caller's responsibility to establish the client site as soon as possible using IOleObject::SetClientSite.
///
///
/// Pointer to the storage to use for the object and any default data or presentation caching established for it.
///
///
/// Address of output pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvObj
/// contains the requested interface pointer on the newly created object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_NOINTERFACE
/// The provided interface identifier is invalid.
///
/// -
/// E_INVALIDARG
/// One or more parameters are invalid.
///
///
///
///
/// The following call to OleCreateLinkToFile:
/// is equivalent to the following call to OleCreateLinkToFileEx:
///
/// Existing instantiation functions (OleCreate, OleCreateFromFile, OleCreateFromData, OleCreateLink, OleCreateLinkToFile, and
/// OleCreateLinkFromData) create only a single presentation or data format cache in the default cache location (within the
/// '\001OlePresXXX' streams of the passed-in IStorage) during instantiation. Plus, these caches must be created when the object next
/// enters the running state. Because most applications require caching at least two presentations (screen and printer) and may
/// require caching data in a different format or location from the handler, applications must typically launch and shut down the
/// object server multiple times in order to prime their data caches during object creation, i.e., Insert Object, Insert Object from
/// File, and Paste Object.
///
///
/// Extended versions of these creation functions solve this problem. OleCreateEx, OleCreateFromFileEx, OleCreateFromDataEx,
/// OleCreateLinkEx, OleCreateLinkToFileEx, and OleCreateLinkFromDataEx, contain the following new parameters: dwFlags to
/// indicate additional options, cFormats to indicate how many formats to cache, rgAdvf, from the ADVF enumeration, to specify the
/// advise flags for each format to be cached, pAdviseSink to indicate whether presentation (default-handler) or data
/// (non-default-handler) caching is required, rgdwConnection to return IDataObject::DAdvise cookies, and rgFormatEtc, an array of
/// formats rather than a single format.
///
///
/// Containers requiring that multiple presentations be cached on their behalf by the object's handler can simply call these
/// functions and specify the number of formats in cFormats, the ADVF flags for each format in rgAdvf, and the set of formats in
/// rgFormatEtc. These containers pass NULL for pAdviseSink.
///
///
/// Containers performing all their own data- or presentation-caching perform these same steps, but pass a non- NULL
/// pAdviseSink. They perform their own caching or manipulation of the object or data during IAdviseSink::OnDataChange. Typically,
/// such containers never establish the advisory connections with ADVF_NODATA, although they are not prevented from doing so.
///
///
/// These new functions are for OLE Compound Documents. Using these functions, applications can avoid the repeated launching and
/// initialization steps required by the current functions. They are targeted at OLE Compound Document container applications that
/// use default data- and presentation-caching, and also at applications that provide their own caching and data transfer from the
/// underlying IDataObject::DAdvise support.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreatelinktofileex HRESULT OleCreateLinkToFileEx( IN LPCOLESTR
// lpszFileName, IN REFIID riid, IN DWORD dwFlags, IN DWORD renderopt, IN ULONG cFormats, IN DWORD *rgAdvf, IN LPFORMATETC
// rgFormatEtc, IN IAdviseSink *lpAdviseSink, OUT DWORD *rgdwConnection, IN LPOLECLIENTSITE pClientSite, IN LPSTORAGE pStg, OUT
// LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "9a333bac-8ee3-4941-8e4b-78a2befceff8")]
public static extern HRESULT OleCreateLinkToFileEx([MarshalAs(UnmanagedType.LPWStr)] string lpszFileName, in Guid riid, OLECREATE dwFlags, OLERENDER renderopt, uint cFormats, [In, Optional] ADVF[] rgAdvf, [In, Optional] FORMATETC[] rgFormatEtc,
[Optional] IAdviseSink lpAdviseSink, [Out, Optional] uint[] rgdwConnection, [Optional] IOleClientSite pClientSite, IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
///
/// Creates and returns an OLE menu descriptor (that is, an OLE-provided data structure that describes the menus) for OLE to use when
/// dispatching menu messages and commands.
///
/// Handle to the combined menu created by the object.
/// Pointer to an array of six LONG values giving the number of menus in each group.
/// Returns the handle to the descriptor, or NULL if insufficient memory is available.
///
/// The OleCreateMenuDescriptor function can be called by the object to create a descriptor for the composite menu. OLE then
/// uses this descriptor to dispatch menu messages and commands. To free the shared menu descriptor when it is no longer needed, the
/// container should call the companion helper function, OleDestroyMenuDescriptor.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreatemenudescriptor HOLEMENU OleCreateMenuDescriptor( IN HMENU
// hmenuCombined, IN LPOLEMENUGROUPWIDTHS lpMenuWidths );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "b4a6b3f1-aee9-4b68-8ffe-24bd497db0a0")]
public static extern HOLEMENU OleCreateMenuDescriptor(HMENU hmenuCombined, in OLEMENUGROUPWIDTHS lpMenuWidths);
///
/// Creates a static object, that contains only a representation, with no native data, from a data transfer object.
/// Note The OLESTREAM to IStorage conversion functions also convert static objects.
///
///
/// Pointer to the IDataObject interface on the data transfer object that holds the data from which the object will be created.
///
///
/// Reference to the identifier of the interface with which the caller is to communicate with the new object (usually IID_IOleObject,
/// defined in the OLE headers as the interface identifier for IOleObject).
///
///
/// Value from the enumeration OLERENDER indicating the locally cached drawing or data-retrieval capabilities that the container
/// wants in the newly created component. It is an error to pass the render options OLERENDER_NONE or OLERENDER_ASIS to this function.
///
///
/// Depending on which of the OLERENDER flags is used as the value of renderopt, may be a pointer to one of the FORMATETC enumeration
/// values. Refer to the OLERENDER enumeration for restrictions.
///
///
/// Pointer to an instance of IOleClientSite, the primary interface through which the object will request services from its
/// container. This parameter can be NULL.
///
/// Pointer to the IStorage interface for storage for the object. This parameter cannot be NULL.
///
/// Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvObj contains the
/// requested interface pointer on the newly created object.
///
/// This function returns S_OK on success.
///
///
/// The OleCreateStaticFromData function can convert any object, as long as it provides an IDataObject interface, to a static
/// object. It is useful in implementing the Convert To Picture option for OLE linking or embedding.
///
///
/// Static objects can be created only if the source supports one of the OLE-rendered clipboard formats: CF_METAFILEPICT, CF_DIB, or
/// CF_ BITMAP, and CF_ENHMETAFILE.
///
///
/// You can also call OleCreateStaticFromData to paste a static object from the clipboard. To determine whether an object is
/// static, call the OleQueryCreateFromData function, which returns OLE_S_STATIC if one of CF_METAFILEPICT, CF_DIB, CF_BITMAP, or
/// CF_ENHMETAFILE is present and an OLE format is not present. This indicates that you should call OleCreateStaticFromData
/// rather than the OleCreateFromData function to create the object.
///
///
/// The new static object is of class CLSID_StaticMetafile in the case of CF_METAFILEPICT, CLSID_StaticDib in the case of CF_DIB or
/// CF_BITMAP, or CLSID_Picture_EnhMetafile in the case of CF_ENHMETAFILE. The static object sets the OLEMISC_STATIC and
/// OLE_CANTLINKINSIDE bits returned from IOleObject::GetMiscStatus. The static object will have the aspect DVASPECT_CONTENT and a
/// LINDEX of -1.
///
///
/// The pSrcDataObject is still valid after OleCreateStaticFromData returns. It is the caller's responsibility to free
/// pSrcDataObject — OLE does not release it.
///
/// There cannot be more than one presentation stream in a static object.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olecreatestaticfromdata HRESULT OleCreateStaticFromData( IN
// LPDATAOBJECT pSrcDataObj, IN REFIID iid, IN DWORD renderopt, IN LPFORMATETC pFormatEtc, IN LPOLECLIENTSITE pClientSite, IN
// LPSTORAGE pStg, OUT LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "847d82f5-149d-48a4-a228-f5551a07a790")]
public static extern HRESULT OleCreateStaticFromData(IDataObject pSrcDataObj, in Guid iid, OLERENDER renderopt, in FORMATETC pFormatEtc, [Optional] IOleClientSite pClientSite, IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
/// Called by the container to free the shared menu descriptor allocated by the OleCreateMenuDescriptor function.
/// Handle to the shared menu descriptor that was returned by the OleCreateMenuDescriptor function.
/// This function does not return a value.
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oledestroymenudescriptor HRESULT OleDestroyMenuDescriptor( IN
// HOLEMENU holemenu );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "dc347d39-a7bb-4bbf-8957-c3fbcff461bf")]
public static extern HRESULT OleDestroyMenuDescriptor(HOLEMENU holemenu);
/// Automatically converts an object to a new class if automatic conversion for that object class is set in the registry.
/// A pointer to the IStorage interface on the storage object to be converted.
///
/// A pointer to the new CLSID for the object being converted. If there was no automatic conversion, this may be the same as the
/// original class.
///
///
///
/// This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following values.
///
///
///
/// Return code
/// Description
///
/// -
/// S_OK
/// No conversion is needed or a conversion was successfully completed.
///
/// -
/// REGDB_E_KEYMISSING
/// The function cannot read a key from the registry.
///
///
///
/// This function can also return any of the error values returned by the OleGetAutoConvert function. When accessing storage and
/// stream objects, see the IStorage::OpenStorage and IStorage::OpenStream methods for possible errors. When it is not possible to
/// determine the existing CLSID or when it is not possible to update the storage object with new information, see the IStream
/// interface for other error return values.
///
///
///
///
/// OleDoAutoConvert automatically converts an object if automatic conversion has previously been specified in the registry by
/// the OleSetAutoConvert function. Object conversion means that the object is permanently associated with a new CLSID. Automatic
/// conversion is typically specified by the setup program for a new version of an object application, so that objects created by its
/// older versions can be automatically updated.
///
/// The storage object must be in the unloaded state when OleDoAutoConvert is called.
///
/// A container application that supports object conversion should call OleDoAutoConvert each time it loads an object. If the
/// container uses the OleLoad helper function, it need not call OleDoAutoConvert explicitly because OleLoad calls it internally.
///
///
/// OleDoAutoConvert first determines whether any conversion is required by calling the OleGetAutoConvert function, which, if
/// no conversion is required, returns S_OK. If the object requires conversion, OleDoAutoConvert modifies and converts the
/// storage object by activating the new object application. The new object application reads the existing data format, but saves the
/// object in the new native format for the object application.
///
///
/// If the object to be automatically converted is an OLE 1 object, the ItemName string is stored in a stream called
/// "\1Ole10ItemName." If this stream does not exist, the object's item name is NULL.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oledoautoconvert HRESULT OleDoAutoConvert( IN LPSTORAGE pStg, OUT
// LPCLSID pClsidNew );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "fe470f8a-b2f0-48a4-a270-77420bd1472a")]
public static extern HRESULT OleDoAutoConvert(IStorage pStg, out Guid pClsidNew);
/// Enables drawing objects more easily. You can use it instead of calling IViewObject::Draw directly.
/// Points to the view object that is to be drawn.
///
/// Specifies how the object is to be represented. Representations include content, an icon, a thumbnail, or a printed document.
/// Valid values are taken from the enumeration DVASPECT. See DVASPECT for more information.
///
/// Specifies the device context on which to draw. Cannot be a metafile device context.
///
/// Points to a RECT structure specifying the rectangle in which the object should be drawn. This parameter is converted to a RECTL
/// structure and passed to IViewObject::Draw.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// OLE_E_BLANK
/// No data to draw from.
///
/// -
/// E_ABORT
/// The draw operation was aborted.
///
/// -
/// VIEW_E_DRAW
/// No data to draw from.
///
/// -
/// OLE_E_INVALIDRECT
/// The rectangle is invalid.
///
/// -
/// E_INVALIDARG
/// One or more parameters are invalid.
///
/// -
/// E_OUTOFMEMORY
/// Insufficient memory for the operation.
///
/// -
/// DV_E_NOIVIEWOBJECT
/// The object doesn't support the IViewObject interface.
///
///
///
///
///
/// The OleDraw helper function calls the QueryInterface method for the object specified (pUnk), asking for an IViewObject interface
/// on that object. Then, OleDraw converts the RECT structure to a RECTL structure, and calls IViewObject::Draw as follows:
///
/// Do not use this function to draw into a metafile because it does not specify the parameter required for drawing into metafiles.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oledraw HRESULT OleDraw( IN LPUNKNOWN pUnknown, IN DWORD dwAspect,
// IN HDC hdcDraw, IN LPCRECT lprcBounds );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "c45c6746-59ea-43bb-9f2b-2182d7a3fc7a")]
public static extern HRESULT OleDraw([MarshalAs(UnmanagedType.IUnknown)] object pUnknown, DVASPECT dwAspect, HDC hdcDraw, in RECT lprcBounds);
///
/// Duplicates the data found in the specified handle and returns a handle to the duplicated data. The source data is in a clipboard
/// format. Use this function to help implement some of the data transfer interfaces such as IDataObject.
///
/// Handle of the source data.
/// Clipboard format of the source data.
///
/// Flags to be used to allocate global memory for the copied data. These flags are passed to GlobalAlloc. If the value of uiFlags is
/// NULL, GMEM_MOVEABLE is used as a default flag.
///
/// On success the HANDLE to the source data is returned; on failure a NULL value is returned.
///
/// The CF_METAFILEPICT, CF_PALETTE, or CF_BITMAP formats receive special handling. They are GDI handles and a new GDI object must be
/// created instead of just copying the bytes. All other formats are duplicated byte-wise.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleduplicatedata HANDLE OleDuplicateData( IN HANDLE hSrc, IN
// CLIPFORMAT cfFormat, IN UINT uiFlags );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "c4ba0b54-e9e1-4c05-b4f8-ce5390cada17")]
public static extern HANDLE OleDuplicateData(HANDLE hSrc, CLIPFORMAT cfFormat, Kernel32.GMEM uiFlags);
///
/// Carries out the clipboard shutdown sequence. It also releases the IDataObject pointer that was placed on the clipboard by the
/// OleSetClipboard function.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// CLIPBRD_E_CANT_OPEN
/// The Windows OpenClipboard function used within OleFlushClipboard failed.
///
/// -
/// CLIPBRD_E_CANT_CLOSE
/// The Windows CloseClipboard function used within OleFlushClipboard failed.
///
///
///
///
///
/// 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.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleflushclipboard HRESULT OleFlushClipboard( );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "18291a91-be7d-42ec-a44a-d1bbfb017c6e")]
public static extern HRESULT OleFlushClipboard();
///
/// Determines whether the registry is set for objects of a specified CLSID to be automatically converted to another CLSID, and if
/// so, retrieves the new CLSID.
///
/// The CLSID for the object.
///
/// A pointer to a variable to receive the new CLSID, if any. If auto-conversion for clsidOld is not set in the registry, clsidOld is
/// returned. The pClsidNew parameter is never NULL.
///
///
///
/// This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following values.
///
///
///
/// Return code
/// Description
///
/// -
/// S_OK
/// A value was successfully returned through the pclsidNew parameter.
///
/// -
/// REGDB_E_CLASSNOTREG
/// The CLSID is not properly registered in the registry.
///
/// -
/// REGDB_E_READREGDB
/// Error reading from the registry.
///
/// -
/// REGDB_E_KEYMISSING
/// Auto-convert is not active or there was no registry entry for the clsidOld parameter.
///
///
///
///
///
/// OleGetAutoConvert returns the AutoConvertTo entry in the registry for the specified object. The
/// AutoConvertTo subkey specifies whether objects of a given CLSID are to be automatically converted to a new CLSID. This is
/// usually used to convert files created by older versions of an application to the current version. If there is no
/// AutoConvertTo entry, this function returns the value of clsidOld.
///
///
/// The OleDoAutoConvert function calls OleGetAutoConvert to determine whether the object specified is to be converted. A
/// container application that supports object conversion should call OleDoAutoConvert each time it loads an object. If the
/// container uses the OleLoad helper function, it need not call OleDoAutoConvert explicitly because OleLoad calls it internally.
///
///
/// To set up automatic conversion of a given class, you can call the OleSetAutoConvert function (typically in the setup program of
/// an application installation). This function uses the AutoConvertTo subkey to tag a class of objects for automatic
/// conversion to a different class of objects. This is a subkey of the CLSID key.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olegetautoconvert HRESULT OleGetAutoConvert( IN REFCLSID clsidOld,
// OUT LPCLSID pClsidNew );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "f84e578a-d2ed-4b7b-9b7c-5d63f12d5781")]
public static extern HRESULT OleGetAutoConvert(in Guid clsidOld, out Guid pClsidNew);
/// Retrieves a data object that you can use to access the contents of the clipboard.
/// Address of IDataObject pointer variable that receives the interface pointer to the clipboard data object.
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// CLIPBRD_E_CANT_OPEN
/// The OpenClipboard function used within OleFlushClipboard failed.
///
/// -
/// CLIPBRD_E_CANT_CLOSE
/// The CloseClipboard function used within OleFlushClipboard failed.
///
///
///
///
/// Caution Clipboard data is not trusted. Parse the data carefully before using it in your application.
///
/// If you are writing an application that can accept data from the clipboard, call the OleGetClipboard function to get a
/// pointer to the IDataObject interface that you can use to retrieve the contents of the clipboard.
///
/// OleGetClipboard handles three cases:
///
/// -
/// The application that placed data on the clipboard with the OleSetClipboard function is still running.
///
/// -
///
/// The application that placed data on the clipboard with the OleSetClipboard function has subsequently called the OleFlushClipboard function.
///
///
/// -
/// There is data from a non-OLE application on the clipboard.
///
///
///
/// In the first case, the clipboard data object returned by OleGetClipboard may forward calls as necessary to the original
/// data object placed on the clipboard and, thus, can potentially make RPC calls.
///
///
/// In the second case, OLE creates a default data object and returns it to the user. Because the data on the clipboard originated
/// from an OleSetClipboard call, the OLE-provided data object contains more accurate information about the type of data on the
/// clipboard. In particular, the original medium (TYMED) on which the data was offered is known. Thus, if a data-source application
/// offers a particular clipboard format, for example cfFOO, on a storage object and calls the OleFlushClipboard function, the
/// storage object is copied into memory and the hglobal memory handle is put on the clipboard. Then, when the OleGetClipboard
/// function creates its default data object, the hglobal from the clipboard again becomes an IStorage 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.
///
///
/// In the third case, OLE still creates a default data object, but there is no special information about the data in the clipboard
/// formats (particularly for application-defined Clipboard formats). Thus, if an hGlobal-based storage medium were put on the
/// clipboard directly by a call to the SetClipboardData function, the FORMATETC enumerator and the IDataObject::QueryGetData method
/// would not indicate that the data was available on a storage medium. A call to the IDataObject::GetData method for TYMED_ISTORAGE
/// would succeed, however. Because of these limitations, it is strongly recommended that OLE-aware applications interact with the
/// clipboard using the OLE clipboard functions.
///
///
/// The clipboard data object created by the OleGetClipboard function has a fairly extensive IDataObject implementation. The
/// OLE-provided data object can convert OLE 1 clipboard format data into the representation expected by an OLE 2 caller. Also, any
/// structured data is available on any structured or flat medium, and any flat data is available on any flat medium. However, GDI
/// objects (such as metafiles and bitmaps) are only available on their respective mediums.
///
///
/// Note that the tymed member of the FORMATETC structure used in the FORMATETC enumerator contains the union of supported
/// mediums. Applications looking for specific information (such as whether CF_TEXT is available on TYMED_HGLOBAL) should do the
/// appropriate bitmasking when checking this value.
///
///
/// If you call the OleGetClipboard function, you should only hold on to the returned IDataObject for a very short time. It
/// consumes resources in the application that offered it.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olegetclipboard HRESULT OleGetClipboard( LPDATAOBJECT *ppDataObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "c5e7badb-339b-48d5-8c9a-3950e2ffe6bf")]
public static extern HRESULT OleGetClipboard(out IDataObject ppDataObj);
///
///
/// Enables Windows Information Protection enlightened applications to retrieve an IDataObject from the OLE Clipboard accompanied by
/// Windows Information Protection information about the data and the source application. This information allows the enlightened
/// application to take over responsibility for applying Windows Information Protection policy, including flying any appropriate UI
/// prompts, and auditing cases where the user explicitly approves copying enterprise data into a personal context.
///
///
/// If the calling application is not enlightened, or is configured as "unallowed" to access enterprise data, then this call behaves
/// exactly like OleGetClipboard - applying policy before deciding what IDataObject to return, and supplying empty strings as output.
///
///
///
/// Address of IDataObject pointer variable that receives the interface pointer to the clipboard data object.
///
///
/// The enterprise id of the application that set the clipboard data. If the data is personal, this will be an empty string.
///
/// The description of the application that set the clipboard.
/// The description of the caller's application to be used in auditing.
/// The description of the data object to be used in auditing.
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// CLIPBRD_E_CANT_OPEN
/// The OpenClipboard function used within OleFlushClipboard failed.
///
/// -
/// CLIPBRD_E_CANT_CLOSE
/// The CloseClipboard function used within OleFlushClipboard failed.
///
///
///
///
/// Caution Clipboard data is not trusted. Parse the data carefully before using it in your application.
///
/// If you are writing an application that can accept data from the clipboard, call the OleGetClipboardWithEnterpriseInfo
/// function to get a pointer to the IDataObject interface that you can use to retrieve the contents of the clipboard.
///
/// OleGetClipboardWithEnterpriseInfo handles three cases:
///
/// -
/// The application that placed data on the clipboard with the OleSetClipboard function is still running.
///
/// -
///
/// The application that placed data on the clipboard with the OleSetClipboard function has subsequently called the OleFlushClipboard function.
///
///
/// -
/// There is data from a non-OLE application on the clipboard.
///
///
///
/// In the first case, the clipboard data object returned by OleGetClipboardWithEnterpriseInfo may forward calls as necessary
/// to the original data object placed on the clipboard and, thus, can potentially make RPC calls.
///
///
/// In the second case, OLE creates a default data object and returns it to the user. Because the data on the clipboard originated
/// from an OleSetClipboard call, the OLE-provided data object contains more accurate information about the type of data on the
/// clipboard. In particular, the original medium (TYMED) on which the data was offered is known. Thus, if a data-source application
/// offers a particular clipboard format, for example cfFOO, on a storage object and calls the OleFlushClipboard function, the
/// storage object is copied into memory and the hglobal memory handle is put on the clipboard. Then, when the
/// OleGetClipboardWithEnterpriseInfo function creates its default data object, the hglobal from the clipboard again becomes
/// an IStorage 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.
///
///
/// In the third case, OLE still creates a default data object, but there is no special information about the data in the clipboard
/// formats (particularly for application-defined Clipboard formats). Thus, if an hGlobal-based storage medium were put on the
/// clipboard directly by a call to the SetClipboardData function, the FORMATETC enumerator and the IDataObject::QueryGetData method
/// would not indicate that the data was available on a storage medium. A call to the IDataObject::GetData method for TYMED_ISTORAGE
/// would succeed, however. Because of these limitations, it is strongly recommended that OLE-aware applications interact with the
/// clipboard using the OLE clipboard functions.
///
///
/// The clipboard data object created by the OleGetClipboardWithEnterpriseInfo function has a fairly extensive IDataObject
/// implementation. The OLE-provided data object can convert OLE 1 clipboard format data into the representation expected by an OLE 2
/// caller. Also, any structured data is available on any structured or flat medium, and any flat data is available on any flat
/// medium. However, GDI objects (such as metafiles and bitmaps) are only available on their respective mediums.
///
///
/// Note that the tymed member of the FORMATETC structure used in the FORMATETC enumerator contains the union of supported
/// mediums. Applications looking for specific information (such as whether CF_TEXT is available on TYMED_HGLOBAL) should do the
/// appropriate bitmasking when checking this value.
///
///
/// If you call the OleGetClipboardWithEnterpriseInfo function, you should only hold on to the returned IDataObject for a very
/// short time. It consumes resources in the application that offered it.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olegetclipboardwithenterpriseinfo HRESULT
// OleGetClipboardWithEnterpriseInfo( IDataObject **dataObject, PWSTR *dataEnterpriseId, PWSTR *sourceDescription, PWSTR
// *targetDescription, PWSTR *dataDescription );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("ole2.h", MSDNShortId = "1DAD2A9A-EDA2-49D2-90F7-2A9022988177")]
public static extern HRESULT OleGetClipboardWithEnterpriseInfo(out IDataObject dataObject, out StrPtrUni dataEnterpriseId, out StrPtrUni sourceDescription, out StrPtrUni targetDescription, out StrPtrUni dataDescription);
/// Returns a handle to a metafile containing an icon and a string label for the specified CLSID.
/// The CLSID for which the icon and string are to be requested.
/// A pointer to the label for the icon.
/// Indicates whether to use the user type string in the CLSID as the icon label.
///
/// If the function succeeds, the return value is a handle to a metafile that contains and icon and label for the specified CLSID.
/// Otherwise, the function returns NULL.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olegeticonofclass HGLOBAL OleGetIconOfClass( IN REFCLSID rclsid,
// LPOLESTR lpszLabel, IN BOOL fUseTypeAsLabel );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "88ac1c14-b5a8-4100-9fa5-d7af35052b48")]
public static extern SafeHGlobalHandle OleGetIconOfClass(in Guid rclsid, [Optional, MarshalAs(UnmanagedType.LPWStr)] string lpszLabel, [MarshalAs(UnmanagedType.Bool)] bool fUseTypeAsLabel);
/// Returns a handle to a metafile containing an icon and string label for the specified file name.
/// A pointer to a file for which the icon and string are to be requested.
/// Indicates whether to use the file name as the icon label.
///
/// If the function succeeds, the return value is a handle to a metafile that contains and icon and label for the specified file. If
/// there is no CLSID in the registration database for the file, then the function returns the string "Document". If lpszPath is
/// NULL, the function returns NULL.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olegeticonoffile HGLOBAL OleGetIconOfFile( LPOLESTR lpszPath, IN
// BOOL fUseFileAsLabel );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "2fa9cd75-4dc6-45a3-aa62-e82bd28289a5")]
public static extern SafeHGlobalHandle OleGetIconOfFile([MarshalAs(UnmanagedType.LPWStr)] string lpszPath, [MarshalAs(UnmanagedType.Bool)] bool fUseFileAsLabel);
///
/// 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.
///
/// This parameter is reserved and must be NULL.
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// S_FALSE
/// The COM library is already initialized on this apartment.
///
/// -
/// OLE_E_WRONGCOMPOBJ
/// The versions of COMPOBJ.DLL and OLE2.DLL on your machine are incompatible with each other.
///
/// -
/// RPC_E_CHANGED_MODE
///
/// A previous call to CoInitializeEx specified the concurrency model for this apartment as multithread apartment (MTA). This could
/// also mean that a change from neutral threaded apartment to single threaded apartment occurred.
///
///
///
///
///
///
/// Applications that use the following functionality must call OleInitialize before calling any other function in the COM library:
///
///
/// -
/// Clipboard
///
/// -
/// Drag and Drop
///
/// -
/// Object linking and embedding (OLE)
///
/// -
/// In-place activation
///
///
///
/// OleInitialize calls CoInitializeEx internally to initialize the COM library on the current apartment. Because OLE
/// operations are not thread-safe, OleInitialize specifies the concurrency model as single-thread apartment.
///
///
/// Once the concurrency model for an apartment is set, it cannot be changed. A call to OleInitialize on an apartment that was
/// previously initialized as multithreaded will fail and return RPC_E_CHANGED_MODE.
///
///
/// You need to initialize the COM library on an apartment before you call any of the library functions except CoGetMalloc, to get a
/// pointer to the standard allocator, and the memory allocation functions.
///
///
/// Typically, the COM library is initialized on an apartment only once. Subsequent calls will succeed, as long as they do not
/// attempt to change the concurrency model of the apartment, but will return S_FALSE. To close the COM library gracefully, each
/// successful call to OleInitialize, including those that return S_FALSE, must be balanced by a corresponding call to OleUninitialize.
///
///
/// Because there is no way to control the order in which in-process servers are loaded or unloaded, do not call OleInitialize
/// or OleUninitialize from the DllMain function.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleinitialize
// HRESULT OleInitialize( IN LPVOID pvReserved );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "9a13e7a0-f2e2-466b-98f5-38d5972fa391")]
public static extern HRESULT OleInitialize([Optional] IntPtr pvReserved);
///
/// Determines whether the data object pointer previously placed on the clipboard by the OleSetClipboard function is still on the clipboard.
///
///
/// Pointer to the IDataObject interface on the data object containing clipboard data of interest, which the caller previously placed
/// on the clipboard.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// S_FALSE
/// The specified pointer is not on the clipboard.
///
///
///
///
/// OleIsCurrentClipboard only works for the data object used in the OleSetClipboard function. It cannot be called by the
/// consumer of the data object to determine if the object that was on the clipboard at the previous OleGetClipboard call is still on
/// the clipboard.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleiscurrentclipboard HRESULT OleIsCurrentClipboard( IN
// LPDATAOBJECT pDataObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "12844504-ef47-4a4d-b31b-f765e0f2ace6")]
public static extern HRESULT OleIsCurrentClipboard(IDataObject pDataObj);
/// Determines whether a compound document object is currently in the running state.
/// Pointer to the IOleObject interface on the object of interest.
/// The return value is TRUE if the object is running; otherwise, it is FALSE.
///
/// You can use OleIsRunning and IRunnableObject::IsRunning interchangeably. OleIsRunning queries the object for a
/// pointer to the IRunnableObject interface and calls its IRunnableObject::IsRunning method. If successful, the function
/// returns the results of the call to IRunnableObject::IsRunning.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleisrunning BOOL OleIsRunning( IN LPOLEOBJECT pObject );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "9392666f-c269-4667-aeac-67c68bcc5f06")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool OleIsRunning(IOleObject pObject);
/// Loads into memory an object nested within a specified storage object.
/// Pointer to the IStorage interface on the storage object from which to load the specified object.
///
/// Reference to the identifier of the interface that the caller wants to use to communicate with the object after it is loaded.
///
/// Pointer to the IOleClientSite interface on the client site object being loaded.
///
/// Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppvObj contains the
/// requested interface pointer on the newly loaded object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_NOINTERFACE
/// The object does not support the specified interface.
///
///
/// Additionally, this function can return any of the error values returned by the IPersistStorage::Load method.
///
///
///
/// OLE containers load objects into memory by calling this function. When calling the OleLoad function, the container
/// application passes in a pointer to the open storage object in which the nested object is stored. Typically, the nested object to
/// be loaded is a child storage object to the container's root storage object. Using the OLE information stored with the object, the
/// object handler (usually, the default handler) attempts to load the object. On completion of the OleLoad function, the
/// object is said to be in the loaded state with its object application not running.
///
///
/// Some applications load all of the object's native data. Containers often defer loading the contained objects until required to do
/// so. For example, until an object is scrolled into view and needs to be drawn, it does not need to be loaded.
///
/// The OleLoad function performs the following steps:
///
/// -
/// If necessary, performs an automatic conversion of the object (see the OleDoAutoConvert function).
///
/// -
/// Gets the CLSID from the open storage object by calling the IStorage::Stat method.
///
/// -
///
/// Calls the CoCreateInstance function to create an instance of the handler. If the handler code is not available, the default
/// handler is used (see the OleCreateDefaultHandler function).
///
///
/// -
/// Calls the IOleObject::SetClientSite method with the pClientSite parameter to inform the object of its client site.
///
/// -
///
/// Calls the QueryInterface method for the IPersistStorage interface. If successful, the IPersistStorage::Load method is invoked for
/// the object.
///
///
/// -
/// Queries and returns the interface identified by the riid parameter.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleload HRESULT OleLoad( IN LPSTORAGE pStg, IN REFIID riid, IN
// LPOLECLIENTSITE pClientSite, OUT LPVOID *ppvObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "f2d8bb2e-5bd1-4991-a80c-ed06bfd5c9f9")]
public static extern HRESULT OleLoad(IStorage pStg, in Guid riid, IOleClientSite pClientSite, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
/// Locks an already running object into its running state or unlocks it from its running state.
/// Pointer to the IUnknown interface on the object, which the function uses to query for a pointer to IRunnableObject.
/// TRUE locks the object into its running state. FALSE unlocks the object from its running state.
///
/// TRUE specifies that if the connection being released is the last external lock on the object, the object should close.
/// FALSE specifies that the object should remain open until closed by the user or another process.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_OUTOFMEMORY
/// Insufficient memory for the operation.
///
/// -
/// E_INVALIDARG
/// One or more parameters are invalid.
///
/// -
/// E_UNEXPECTED
/// An unexpected error occurred.
///
///
///
///
///
/// The OleLockRunning function saves you the trouble of calling the IRunnableObject::LockRunning method. You can use
/// OleLockRunning and IRunnableObject::LockRunning interchangeably. With the IUnknown pointer passed in with the
/// pUnknown parameter, OleLockRunning queries for an IRunnableObject pointer. If successful, it calls
/// IRunnableObject::LockRunning and returns the results of the call.
///
/// For more information on using this function, see IRunnableObject::LockRunning.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olelockrunning HRESULT OleLockRunning( IN LPUNKNOWN pUnknown, IN
// BOOL fLock, IN BOOL fLastUnlockCloses );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "84941a59-6880-4824-b4b9-cd1b52d2bffb")]
public static extern HRESULT OleLockRunning([MarshalAs(UnmanagedType.IUnknown)] object pUnknown, [MarshalAs(UnmanagedType.Bool)] bool fLock, [MarshalAs(UnmanagedType.Bool)] bool fLastUnlockCloses);
/// Creates a metafile in which the specified icon and label are drawn.
///
/// Handle to the icon that is to be drawn into the metafile. This parameter can be NULL. If hIcon is NULL, this
/// function returns NULL without creating a metafile.
///
///
/// The icon label. This parameter can be NULL. If lpszLabel is NULL, the resulting metafile will not include a label.
///
///
/// The path and file name of the icon file. This string can be obtained through the user interface or from the registration
/// database. This parameter can be NULL.
///
///
/// The location of the icon within the file named by lpszSourceFile, expressed as an offset in bytes from the beginning of file.
///
///
///
/// A global handle to a METAFILEPICT structure containing the icon and label. The metafile uses the MM_ANISOTROPIC mapping mode.
///
///
/// If an error occurs, the returned handle is NULL. In this case, the caller can call GetLastError to obtain further information.
///
///
///
/// This function is called by OleGetIconOfFile and OleGetIconOfClass.
///
/// If lpszSourceFile is not NULL and iIconIndex is not 0, the name of the source file passed in lpszSourceFile and the index
/// passed by iIconIndex are added to the created metafile as a comment record.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olemetafilepictfromiconandlabel HGLOBAL
// OleMetafilePictFromIconAndLabel( IN HICON hIcon, LPOLESTR lpszLabel, LPOLESTR lpszSourceFile, IN UINT iIconIndex );
[DllImport(Lib.Ole32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "627a79eb-46dd-4df7-a0d6-cab37b73387a")]
public static extern SafeHGlobalHandle OleMetafilePictFromIconAndLabel(HICON hIcon, [MarshalAs(UnmanagedType.LPWStr), Optional] string lpszLabel, [MarshalAs(UnmanagedType.LPWStr), Optional] string lpszSourceFile, [In] uint iIconIndex);
/// Increments or decrements an external reference that keeps an object in the running state.
/// Pointer to the IUnknown interface on the object that is to be locked or unlocked.
///
/// Whether the object is visible. If TRUE, OLE increments the reference count to hold the object visible and alive regardless
/// of external or internal IUnknown::AddRef and IUnknown::Release operations, registrations, or revocation. If FALSE, OLE
/// releases its hold (decrements the reference count) and the object can be closed.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_OUTOFMEMORY
/// Insufficient memory for the operation.
///
/// -
/// E_INVALIDARG
/// One or more parameters are invalid.
///
/// -
/// E_UNEXPECTED
/// An unexpected error occurred.
///
///
///
///
/// The OleNoteObjectVisible function calls the CoLockObjectExternal function. It is provided as a separate function to
/// reinforce the need to lock an object when it becomes visible to the user and to release the object when it becomes invisible.
/// This creates a strong lock on behalf of the user to ensure that the object cannot be closed by its container while it is visible.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olenoteobjectvisible HRESULT OleNoteObjectVisible( IN LPUNKNOWN
// pUnknown, IN BOOL fVisible );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "f140f068-3115-4389-b67b-6d41d12f7525")]
public static extern HRESULT OleNoteObjectVisible([MarshalAs(UnmanagedType.IUnknown)] object pUnknown, [MarshalAs(UnmanagedType.Bool)] bool fVisible);
///
/// Checks whether a data object has one of the formats that would allow it to become an embedded object through a call to either the
/// OleCreateFromData or OleCreateStaticFromData function.
///
/// Pointer to the IDataObject interface on the data transfer object to be queried.
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// S_FALSE
/// No formats are present that support either embedded- or static-object creation.
///
/// -
/// OLE_S_STATIC
/// Formats that support static-object creation are present.
///
///
///
///
///
/// When an application retrieves a data transfer object through a call to the OleGetClipboard function, the application should call
/// OleQueryCreateFromData as part of the process of deciding to enable or disable the Edit/Paste or Edit/Paste
/// Special... commands. It tests for the presence of the following formats in the data object:
///
///
/// -
/// CF_EMBEDDEDOBJECT
///
/// -
/// CF_EMBEDSOURCE
///
/// -
/// cfFileName
///
/// -
/// CF_METAFILEPICT
///
/// -
/// CF_DIB
///
/// -
/// CF_BITMAP
///
/// -
/// CF_ENHMETAFILE
///
///
///
/// Determining that the data object has one of these formats does not absolutely guarantee that the object creation will succeed,
/// but is intended to help the process.
///
///
/// If OleQueryCreateFromData finds one of the CF_METAFILEPICT, CF_BITMAP, CF_DIB, or CF_ENHMETAFILE formats and none of the
/// other formats, it returns OLE_S_STATIC, indicating that you should call the OleCreateStaticFromData function to create the
/// embedded object.
///
///
/// If OleQueryCreateFromData finds one of the other formats (CF_EMBEDDEDOBJECT, CF_EMBEDSOURCE, or cfFileName), even in
/// combination with the static formats, it returns S_OK, indicating that you should call the OleCreateFromData function to create
/// the embedded object.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olequerycreatefromdata HRESULT OleQueryCreateFromData( IN
// LPDATAOBJECT pSrcDataObject );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "58fffb8c-9726-4801-84ce-6fb670b865c8")]
public static extern HRESULT OleQueryCreateFromData([In] IDataObject pSrcDataObject);
///
/// Determines whether an OLE linked object (rather than an OLE embedded object) can be created from a clipboard data object.
///
///
/// Pointer to the IDataObject interface on the clipboard data object from which the object is to be created.
///
/// Returns S_OK if the OleCreateLinkFromData function can be used to create the linked object; otherwise S_FALSE.
///
/// The OleQueryLinkFromData function is similar to the OleQueryCreateFromData function, but determines whether an OLE linked
/// object (rather than an OLE embedded object) can be created from the clipboard data object. If the return value is S_OK, the
/// application can then attempt to create the object with a call to OleCreateLinkFromData. A successful return from
/// OleQueryLinkFromData does not, however, guarantee the successful creation of a link.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olequerylinkfromdata HRESULT OleQueryLinkFromData( IN LPDATAOBJECT
// pSrcDataObject );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "9ebdcd7f-06c1-4464-a66c-4d134a6b5d36")]
public static extern HRESULT OleQueryLinkFromData(IDataObject pSrcDataObject);
///
/// Creates an enumeration object that can be used to enumerate data formats that an OLE object server has registered in the system
/// registry. An object application or object handler calls this function when it must enumerate those formats. Developers of custom
/// DLL object applications use this function to emulate the behavior of the default object handler.
///
/// CLSID of the class whose formats are being requested.
///
/// Indicates whether to enumerate formats that can be passed to IDataObject::GetData or formats that can be passed to
/// IDataObject::SetData. Possible values are taken from the enumeration DATADIR.
///
/// Address of IEnumFORMATETC pointer variable that receives the interface pointer to the enumeration object.
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_OUTOFMEMORY
/// Insufficient memory for the operation.
///
/// -
/// REGDB_E_CLASSNOTREG
/// There is no CLSID registered for the class object.
///
/// -
/// REGDB_E_READREGDB
/// There was an error reading the registry.
///
/// -
/// OLE_E_REGDB_KEY
/// The DataFormats/GetSet key is missing from the registry.
///
///
///
///
///
/// Object applications can ask OLE to create an enumeration object for FORMATETC structures to enumerate supported data formats in
/// one of two ways. One way is to call OleRegEnumFormatEtc. The other is to return OLE_S_USEREG in response to calls by the
/// default object handler to IDataObject::EnumFormatEtc. OLE_S_USEREG instructs the default handler to call
/// OleRegEnumFormatEtc. Because DLL object applications cannot return OLE_S_USEREG, they must call OleRegEnumFormatEtc
/// rather than delegating the job to the object handler. With the supplied IEnumFORMATETC pointer to the object, you can call the
/// standard enumeration object methods to do the enumeration.
///
///
/// The OleRegEnumFormatEtc function and its sibling functions, OleRegGetUserType, OleRegGetMiscStatus, and OleRegEnumVerbs,
/// provide a way for developers of custom DLL object applications to emulate the behavior of OLE's default object handler in getting
/// information about objects from the registry. By using these functions, you avoid the considerable work of writing your own, and
/// the pitfalls inherent in working directly in the registry. In addition, you get future enhancements and optimizations of these
/// functions without having to code them yourself.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleregenumformatetc HRESULT OleRegEnumFormatEtc( IN REFCLSID
// clsid, IN DWORD dwDirection, LPENUMFORMATETC *ppenum );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "6caebc68-a136-40f2-92d8-7f8003c18e5c")]
public static extern HRESULT OleRegEnumFormatEtc(in Guid clsid, DATADIR dwDirection, out IEnumFORMATETC ppenum);
///
/// Supplies an enumeration of the registered verbs for the specified class. Developers of custom DLL object applications use this
/// function to emulate the behavior of the default object handler.
///
/// Class identifier whose verbs are being requested.
/// Address of IEnumOLEVERB* pointer variable that receives the interface pointer to the new enumeration object.
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// OLEOBJ_E_NOVERBS
/// No verbs are registered for the class.
///
/// -
/// REGDB_E_CLASSNOTREG
/// No CLSID is registered for the class object.
///
/// -
/// REGDB_E_READREGDB
/// An error occurred reading the registry.
///
/// -
/// OLE_E_REGDB_KEY
/// The DataFormats/GetSet key is missing from the registry.
///
///
///
///
///
/// Object applications can ask OLE to create an enumeration object for OLEVERB structures to enumerate supported verbs in one of two
/// ways. One way is to call OleRegEnumVerbs. The other way is to return OLE_S_USEREG in response to calls by the default
/// object handler to IOleObject::EnumVerbs. OLE_S_USEREG instructs the default handler to call OleRegEnumVerbs. Because DLL
/// object applications cannot return OLE_S_USEREG, they must call OleRegEnumVerbs rather than delegating the job to the
/// object handler. With the supplied IEnumOLEVERB pointer to the object, you can call the standard enumeration object methods to do
/// the enumeration.
///
///
/// The OleRegEnumVerbs function and its sibling functions, OleRegGetUserType, OleRegGetMiscStatus, and OleRegEnumFormatEtc,
/// provide a way for developers of custom DLL object applications to emulate the behavior of OLE's default object handler in getting
/// information about objects from the registry. By using these functions, you avoid the considerable work of writing your own, and
/// the pitfalls inherent in working directly in the registry. In addition, you get future enhancements and optimizations of these
/// functions without having to code them yourself.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleregenumverbs HRESULT OleRegEnumVerbs( IN REFCLSID clsid,
// LPENUMOLEVERB *ppenum );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "25cd0876-90b6-4fa3-b180-ffa0c3b51497")]
public static extern HRESULT OleRegEnumVerbs(in Guid clsid, out IEnumOLEVERB ppenum);
///
/// Returns miscellaneous information about the presentation and behaviors supported by the specified CLSID from the registry.
/// This function is used by developers of custom DLL object applications to emulate the behavior of the OLE default handler.
///
/// The CLSID of the class for which status information is to be requested.
///
/// The presentation aspect of the class for which information is requested. Possible values are taken from the DVASPECT enumeration.
///
/// A pointer to the variable that receives the status information.
///
/// This function can return the standard return value E_OUTOFMEMORY, as well as the following values.
///
///
/// Return code
/// Description
///
/// -
/// S_OK
/// The status information was returned successfully.
///
/// -
/// REGDB_E_CLASSNOTREG
/// No CLSID is registered for the class object.
///
/// -
/// REGDB_E_READREGDB
/// There was an error reading from the registry.
///
/// -
/// OLE_E_REGDB_KEY
/// The GetMiscStatus key is missing from the registry.
///
///
///
///
///
/// Object applications can ask OLE to get miscellaneous status information in one of two ways. One way is to call
/// OleRegGetMiscStatus. The other is to return OLE_S_USEREG in response to calls by the default object handler to
/// IOleObject::GetMiscStatus. OLE_S_USEREG instructs the default handler to call OleRegGetMiscStatus. Because DLL object
/// applications cannot return OLE_S_USEREG, they must call OleRegGetMiscStatus rather than delegating the job to the object handler.
///
///
/// OleRegGetMiscStatus and its sibling functions, OleRegGetUserType, OleRegEnumFormatEtc, and OleRegEnumVerbs, provide a way
/// for developers of custom DLL object applications to emulate the behavior of OLE's default object handler in getting information
/// about objects from the registry. By using these functions, you avoid the considerable work of writing your own, and the pitfalls
/// inherent in working directly in the registry. In addition, you get future enhancements and optimizations of these functions
/// without having to code them yourself.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olereggetmiscstatus HRESULT OleRegGetMiscStatus( IN REFCLSID
// clsid, IN DWORD dwAspect, OUT DWORD *pdwStatus );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "3166955f-4f7a-4904-a7fb-ebdfb8e56baf")]
public static extern HRESULT OleRegGetMiscStatus(in Guid clsid, DVASPECT dwAspect, out uint pdwStatus);
///
/// Gets the user type of the specified class from the registry.
/// Developers of custom DLL object applications use this function to emulate the behavior of the OLE default handler.
///
/// The CLSID of the class for which the user type is to be requested.
/// The form of the user-presentable string. Possible values are taken from the enumeration USERCLASSTYPE.
/// A pointer to a string that receives the user type.
///
/// This function can return the standard return value E_OUTOFMEMORY, as well as the following values.
///
///
/// Return code
/// Description
///
/// -
/// S_OK
/// The user type was returned successfully.
///
/// -
/// REGDB_E_CLASSNOTREG
/// No CLSID is registered for the class object.
///
/// -
/// REGDB_E_READREGDB
/// There was an error reading from the registry.
///
/// -
/// OLE_E_REGDB_KEY
/// The ProgID = MainUserTypeName and CLSID = MainUserTypeName keys are missing from the registry.
///
///
///
///
///
/// Object applications can ask OLE to get the user type name of a specified class in one of two ways. One way is to call
/// OleRegGetUserType. The other is to return OLE_S_USEREG in response to calls by the default object handler to
/// IOleObject::GetUserType. OLE_S_USEREG instructs the default handler to call OleRegGetUserType. Because DLL object
/// applications cannot return OLE_S_USEREG, they must call OleRegGetUserType, rather than delegating the job to the object handler.
///
///
/// The OleRegGetUserType function and its sibling functions, OleRegGetMiscStatus, OleRegEnumFormatEtc, and OleRegEnumVerbs,
/// provide a way for developers of custom DLL object applications to emulate the behavior of OLE's default object handler in getting
/// information about objects from the registry. By using these functions, you avoid the considerable work of writing your own, and
/// the pitfalls inherent in working directly in the registry. In addition, you get future enhancements and optimizations of these
/// functions without having to code them yourself.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olereggetusertype HRESULT OleRegGetUserType( IN REFCLSID clsid, IN
// DWORD dwFormOfType, LPOLESTR *pszUserType );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "492a4084-494e-4d78-8f3a-853ec486a2d6")]
public static extern HRESULT OleRegGetUserType(in Guid clsid, USERCLASSTYPE dwFormOfType, [MarshalAs(UnmanagedType.LPWStr)] out string pszUserType);
/// Puts an OLE compound document object into the running state.
///
/// Pointer to the IUnknown interface on the object, with which it will query for a pointer to the IRunnableObject interface, and
/// then call its Run method.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// OLE_E_CLASSDIFF
/// The source of an OLE link has been converted to a different class.
///
///
///
///
///
/// 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.
///
/// For more information on using this function, see IRunnableObject::Run.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olerun HRESULT OleRun( IN LPUNKNOWN pUnknown );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "9035f996-b163-4855-aa9d-184b77072ead")]
public static extern HRESULT OleRun([In, MarshalAs(UnmanagedType.IUnknown)] object pUnknown);
/// Saves an object opened in transacted mode into the specified storage object.
/// Pointer to the IPersistStorage interface on the object to be saved.
///
/// Pointer to the IStorage interface on the destination storage object to which the object indicated in pPS is to be saved.
///
///
/// TRUE indicates that pStg is the same storage object from which the object was loaded or created; FALSE indicates
/// that pStg was loaded or created from a different storage object.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// STGMEDIUM_E_FULL
///
/// The object could not be saved due to lack of disk space. This function can also return any of the error values returned by the
/// IPersistStorage::Save method.
///
///
///
///
///
///
/// The OleSave helper function handles the common situation in which an object is open in transacted mode and is then to be
/// saved into the specified storage object which uses the OLE-provided compound file implementation. Transacted mode means that
/// changes to the object are buffered until either of the IStorage::Commit or IStorage::Revert is called. Callers can handle other
/// situations by calling the IPersistStorage and IStorage interfaces directly.
///
/// OleSave does the following:
///
/// -
/// Calls the IPersist::GetClassID method to get the CLSID of the object.
///
/// -
/// Writes the CLSID to the storage object using the WriteClassStg function.
///
/// -
/// Calls the IPersistStorage::Save method to save the object.
///
/// -
/// If there were no errors on the save; calls the IStorage::Commit method to commit the changes.
///
///
///
/// Note Static objects are saved into a stream called CONTENTS. Static metafile objects get saved in "placeable metafile
/// format" and static DIB data gets saved in "DIB file format." These formats are defined to be the OLE standards for metafile and
/// DIB. All data transferred using an IStream interface or a file (that is, via IDataObject::GetDataHere) must be in these formats.
/// Also, all objects whose default file format is a metafile or DIB must write their data into a CONTENTS stream using these
/// standard formats.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olesave HRESULT OleSave( LPPERSISTSTORAGE pPS, LPSTORAGE pStg,
// BOOL fSameAsLoad );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "b8d8e1af-05a3-42f5-8672-910a2606e613")]
public static extern HRESULT OleSave(IPersistStorage pPS, IStorage pStg, [MarshalAs(UnmanagedType.Bool)] bool fSameAsLoad);
/// Saves an object with the IPersistStream interface on it to the specified stream.
///
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// STGMEDIUM_E_FULL
/// The object could not be saved due to lack of disk space.
///
/// -
/// OLE_E_BLANK
/// The pPStm parameter is NULL.
///
///
///
/// This function can also return any of the error values returned by the WriteClassStm function or the IPersistStream::Save method.
///
///
///
///
/// This function simplifies saving an object that implements the IPersistStream interface to a stream. In this stream, the object's
/// CLSID precedes its data. When the stream is retrieved, the CLSID permits the proper code to be associated with the data. The
/// OleSaveToStream function does the following:
///
///
/// -
/// Calls the IPersist::GetClassID method to get the object's CLSID.
///
/// -
/// Writes the CLSID to the stream with the WriteClassStm function.
///
/// -
/// Calls the IPersistStream::Save method with fClearDirty set to TRUE, which clears the dirty bit in the object.
///
///
/// The companion helper, OleLoadFromStream, loads objects saved in this way.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olesavetostream HRESULT OleSaveToStream( IN LPPERSISTSTREAM pPStm,
// IN LPSTREAM pStm );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "0085c6a8-1a94-4379-9937-c8d792d130da")]
public static extern HRESULT OleSaveToStream([In] IPersistStream pPStm, [In] IStream pStm);
/// Specifies a CLSID for automatic conversion to a different class when an object of that class is loaded.
/// The CLSID of the object class to be converted.
///
/// The CLSID of the object class that should replace clsidOld. This new CLSID replaces any existing auto-conversion information in
/// the registry for clsidOld. If this value is CLSID_NULL, any existing auto-conversion information for clsidOld is removed from the registry.
///
///
///
/// This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following values.
///
///
///
/// Return code
/// Description
///
/// -
/// S_OK
/// The object was tagged successfully.
///
/// -
/// REGDB_E_CLASSNOTREG
/// The CLSID is not properly registered in the registry.
///
/// -
/// REGDB_E_READREGDB
/// Error reading from the registry.
///
/// -
/// REGDB_E_WRITEREGDB
/// Error writing to the registry.
///
/// -
/// REGDB_E_KEYMISSING
/// Cannot read a key from the registry.
///
///
///
///
///
/// OleSetAutoConvert goes to the system registry, finds the AutoConvertTo subkey under the CLSID specified by
/// clsidOld, and sets it to clsidNew. This function does not validate whether an appropriate registry entry for clsidNew currently
/// exists. These entries appear in the registry as subkeys of the CLSID key.
///
///
/// Object conversion means that the object's data is permanently associated with a new CLSID. Automatic conversion is typically
/// specified in the setup program of a new version of an object application, so objects created by its older versions can be
/// automatically updated to the new version.
///
///
/// For example, it may be necessary to convert spreadsheets that were created with earlier versions of a spreadsheet application to
/// the new version. The spreadsheet objects from earlier versions have different CLSIDs than the new version. For each earlier
/// version that you want automatically updated, you would call OleSetAutoConvert in the setup program, specifying the CLSID
/// of the old version, and that of the new one. Then, whenever a user loads an object from a previous version, it would be
/// automatically updated. To support automatic conversion of objects, a server that supports conversion must be prepared to manually
/// convert objects that have the format of an earlier version of the server. Automatic conversion relies internally on this
/// manual-conversion support.
///
///
/// Before setting the desired AutoConvertTo value, setup programs should also call OleSetAutoConvert to remove any
/// existing conversion for the new class, by specifying the new class as the clsidOld parameter, and setting the clsidNew parameter
/// to CLSID_NULL.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olesetautoconvert HRESULT OleSetAutoConvert( IN REFCLSID clsidOld,
// IN REFCLSID clsidNew );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "39abf385-962a-4b20-b319-501c8130e050")]
public static extern HRESULT OleSetAutoConvert(in Guid clsidOld, in Guid clsidNew);
///
/// Places a pointer to a specific data object onto the clipboard. This makes the data object accessible to the OleGetClipboard function.
///
///
/// Pointer to the IDataObject interface on the data object from which the data to be placed on the clipboard can be obtained. This
/// parameter can be NULL; in which case the clipboard is emptied.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// CLIPBRD_E_CANT_OPEN
/// The OpenClipboard function used within OleSetClipboard failed.
///
/// -
/// CLIPBRD_E_CANT_EMPTY
/// The EmptyClipboard function used within OleSetClipboard failed.
///
/// -
/// CLIPBRD_E_CANT_CLOSE
/// The CloseClipboard function used within OleSetClipboard failed.
///
/// -
/// CLIPBRD_E_CANT_SET
/// The SetClipboardData function used within OleSetClipboard failed.
///
///
///
///
/// If you are writing an application that can act as the source of a clipboard operation, you must do the following:
///
/// -
///
/// Create a data object (on which is the IDataObject interface) for the data being copied or cut to the clipboard. This object
/// should be the same object used in OLE drag-and-drop operations.
///
///
/// -
///
/// Call OleSetClipboard to place the IDataObject pointer onto the clipboard, so it is accessible to the OleGetClipboard
/// function. OleSetClipboard also calls the IUnknown::AddRef method on your data object.
///
///
/// -
///
/// If you wish, release the data object after you have placed it on the clipboard to free the IUnknown::AddRef counter in your application.
///
///
/// -
///
/// If the user is cutting data (deleting it from the document and putting it on to the clipboard), remove the data from the document.
///
///
///
///
/// All formats are offered on the clipboard using delayed rendering (the clipboard contains only a pointer to the data object unless
/// a call to OleFlushClipboard renders the data onto the clipboard). The formats necessary for OLE 1 compatibility are synthesized
/// from the OLE 2 formats that are present and are also put on the clipboard.
///
///
/// The OleSetClipboard function assigns ownership of the clipboard to an internal OLE window handle. The reference count of
/// the data object is increased by 1, to enable delayed rendering. The reference count is decreased by a call to the
/// OleFlushClipboard function or by a subsequent call to OleSetClipboard specifying NULL as the parameter value (which
/// clears the clipboard).
///
///
/// When an application opens the clipboard (either directly or indirectly by calling the OpenClipboard function), the clipboard
/// cannot be used by any other application until it is closed. If the clipboard is currently open by another application,
/// OleSetClipboard fails. The internal OLE window handle satisfies WM_RENDERFORMAT messages by delegating them to the
/// IDataObject implementation on the data object that is on the clipboard.
///
///
/// Specifying NULL as the parameter value for OleSetClipboard empties the current clipboard. If the contents of the
/// clipboard are the result of a previous OleSetClipboard call and the clipboard has been released, the IDataObject pointer
/// that was passed to the previous call is released. The clipboard owner should use this as a signal that the data it previously
/// offered is no longer on the clipboard.
///
///
/// If you need to leave the data on the clipboard after your application is closed, you should call OleFlushClipboard rather than
/// calling OleSetClipboard with a NULL parameter value.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olesetclipboard HRESULT OleSetClipboard( IN LPDATAOBJECT pDataObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "741def10-d2b5-4395-8049-1eba2e29b0e8")]
public static extern HRESULT OleSetClipboard([In] IDataObject pDataObj);
///
/// Notifies an object that it is embedded in an OLE container, which ensures that reference counting is done correctly for
/// containers that support links to embedded objects.
///
/// Pointer to the IUnknown interface of the object.
/// TRUE if the object is an embedded object; FALSE otherwise.
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_OUTOFMEMORY
/// Insufficient memory for the operation.
///
/// -
/// E_INVALIDARG
/// One or more parameters are invalid.
///
/// -
/// E_UNEXPECTED
/// An unexpected error occurred.
///
///
///
///
/// The OleSetContainedObject function notifies an object that it is embedded in an OLE container. The implementation of
/// OleSetContainedObject was changed in OLE 2.01 to coincide with the publication of the IRunnableObject interface. You can
/// use OleSetContainedObject and the IRunnableObject::SetContainedObject method interchangeably. The
/// OleSetContainedObject function queries the object for a pointer to the IRunnableObject interface. If successful,
/// the function returns the results of calling IRunnableObject::SetContainedObject.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olesetcontainedobject HRESULT OleSetContainedObject( IN LPUNKNOWN
// pUnknown, IN BOOL fContained );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "154aa6f0-3c02-4139-8c8e-c2112b015fe0")]
public static extern HRESULT OleSetContainedObject([In, MarshalAs(UnmanagedType.IUnknown)] object pUnknown, [MarshalAs(UnmanagedType.Bool)] bool fContained);
/// Installs or removes OLE dispatching code from the container's frame window.
///
/// Handle to the composite menu descriptor returned by the OleCreateMenuDescriptor function. If NULL, the dispatching code is unhooked.
///
/// Handle to the container's frame window where the in-place composite menu is to be installed.
///
/// Handle to the object's in-place activation window. OLE dispatches menu messages and commands to this window.
///
/// Pointer to the IOleInPlaceFrame interface on the container's frame window.
/// Pointer to the IOleInPlaceActiveObject interface on the active in-place object.
/// This function returns S_OK on success.
///
///
/// The container should call OleSetMenuDescriptor to install the dispatching code on hwndFrame when the object calls the
/// IOleInPlaceFrame::SetMenu method, or to remove the dispatching code by passing NULL as the value for holemenu to OleSetMenuDescriptor.
///
///
/// If both the lpFrame and lpActiveObj parameters are non- NULL, OLE installs the context-sensitive help F1 message filter
/// for the application. Otherwise, the application must supply its own message filter.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-olesetmenudescriptor HRESULT OleSetMenuDescriptor( IN HOLEMENU
// holemenu, IN HWND hwndFrame, IN HWND hwndActiveObject, IN LPOLEINPLACEFRAME lpFrame, IN LPOLEINPLACEACTIVEOBJECT lpActiveObj );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "c80fe36d-5093-4814-83a9-0c11c5a7cf5f")]
public static extern HRESULT OleSetMenuDescriptor([In] HOLEMENU holemenu, [In] HWND hwndFrame, [In] HWND hwndActiveObject, [In] IOleInPlaceFrame lpFrame, [In] IOleInPlaceActiveObject lpActiveObj);
///
/// Called by the object application, allows an object's container to translate accelerators according to the container's accelerator table.
///
/// Pointer to the IOleInPlaceFrame interface to which the keystroke might be sent.
/// Pointer to an OLEINPLACEFRAMEINFO structure containing the accelerator table obtained from the container.
/// Pointer to an MSG structure containing the keystroke.
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// E_FAIL
/// The object should continue processing this message.
///
///
///
///
///
/// Object servers call OleTranslateAccelerator to allow the object's container to translate accelerator keystrokes according
/// to the container's accelerator table, pointed to by lpFrameInfo. While a contained object is the active object, the object's
/// server always has first chance at translating any messages received. If this is not desired, the server calls
/// OleTranslateAccelerator to give the object's container a chance. If the keyboard input matches an accelerator found in the
/// container-provided accelerator table, OleTranslateAccelerator passes the message and its command identifier on to the
/// container through the IOleInPlaceFrame::TranslateAccelerator method. This method returns S_OK if the keystroke is consumed;
/// otherwise it returns S_FALSE.
///
///
/// Accelerator tables for containers should be defined so they will work properly with object applications that do their own
/// accelerator keystroke translations. These tables should take the form:
///
///
/// This is the most common way to describe keyboard accelerators. Failure to do so can result in keystrokes being lost or sent to
/// the wrong object during an in-place session.
///
/// Objects can call the IsAccelerator function to see whether the accelerator keystroke belongs to the object or the container.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oletranslateaccelerator HRESULT OleTranslateAccelerator( IN
// LPOLEINPLACEFRAME lpFrame, IN LPOLEINPLACEFRAMEINFO lpFrameInfo, IN LPMSG lpmsg );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "c590efef-7f03-4ae6-a35f-eff2fc4da3d9")]
public static extern HRESULT OleTranslateAccelerator([In] IOleInPlaceFrame lpFrame, in OLEINPLACEFRAMEINFO lpFrameInfo, in MSG lpmsg);
///
/// 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.
///
[DllImport(Lib.Ole32, ExactSpelling = true, SetLastError = false)]
[PInvokeData("Ole2.h", MSDNShortId = "ms691326")]
public static extern void OleUninitialize();
///
/// The ReadFmtUserTypeStg function returns the clipboard format and user type previously saved with the WriteFmtUserTypeStg function.
///
/// Pointer to the IStorage interface on the storage object from which the information is to be read.
///
/// Pointer to where the clipboard format is to be written on return. It can be NULL, indicating the format is of no interest
/// to the caller.
///
///
/// Address of LPWSTR pointer variable that receives a pointer to the null-terminated Unicode user-type string. The caller can
/// specify NULL for this parameter, which indicates that the user type is of no interest. This function allocates memory for
/// the string. The caller is responsible for freeing the memory with CoTaskMemFree.
///
///
/// This function supports the standard return values E_FAIL, E_INVALIDARG, and E_OUTOFMEMORY, in addition to the following:
/// This function also returns any of the error values returned by the ISequentialStream::Read method.
///
///
/// ReadFmtUserTypeStg returns the clipboard format and the user type string from the specified storage object. The
/// WriteClassStg function must have been called before calling the ReadFmtUserTypeStg function.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-readfmtusertypestg HRESULT ReadFmtUserTypeStg( IN LPSTORAGE pstg,
// OUT CLIPFORMAT *pcf, LPOLESTR *lplpszUserType );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "6f26550d-c094-4150-b8ef-2da1d052c1ff")]
public static extern HRESULT ReadFmtUserTypeStg([In] IStorage pstg, out CLIPFORMAT pcf, [MarshalAs(UnmanagedType.LPWStr)] out string lplpszUserType);
///
/// Registers the specified window as one that can be the target of an OLE drag-and-drop operation and specifies the IDropTarget
/// instance to use for drop operations.
///
/// Handle to a window that can be a target for an OLE drag-and-drop operation.
///
/// Pointer to the IDropTarget interface on the object that is to be the target of a drag-and-drop operation in a specified window.
/// This interface is used to communicate OLE drag-and-drop information for that window.
///
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// DRAGDROP_E_INVALIDHWND
/// Invalid handle returned in the hwnd parameter.
///
/// -
/// DRAGDROP_E_ALREADYREGISTERED
/// The specified window has already been registered as a drop target.
///
/// -
/// E_OUTOFMEMORY
/// Insufficient memory for the operation.
///
///
///
/// Note If you use CoInitialize or CoInitializeEx instead of OleInitialize to initialize COM, RegisterDragDrop will
/// always return an E_OUTOFMEMORY error.
///
///
///
///
/// If your application can accept dropped objects during OLE drag-and-drop operations, you must call the RegisterDragDrop
/// function. Do this whenever one of your application windows is available as a potential drop target, i.e., when the window appears
/// unobscured on the screen.
///
///
/// The application thread that calls the RegisterDragDrop function must be pumping messages, presumably by calling the
/// GetMessage function with a NULL hWnd parameter, because OLE creates windows on the thread that need messages processed. If
/// this requirement is not met, any application that drags an object over the window that is registered as a drop target will hang
/// until the target application closes.
///
///
/// The RegisterDragDrop function only registers one window at a time, so you must call it for each application window capable
/// of accepting dropped objects.
///
///
/// As the mouse passes over unobscured portions of the target window during an OLE drag-and-drop operation, the DoDragDrop function
/// calls the specified IDropTarget::DragOver method for the current window. When a drop operation actually occurs in a given window,
/// the DoDragDrop function calls IDropTarget::Drop.
///
/// The RegisterDragDrop function also calls the IUnknown::AddRef method on the IDropTarget pointer.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-registerdragdrop HRESULT RegisterDragDrop( IN HWND hwnd, IN
// LPDROPTARGET pDropTarget );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "00726271-4436-41f5-b7cc-666cd77216bc")]
public static extern HRESULT RegisterDragDrop([In] HWND hwnd, [In] IDropTarget pDropTarget);
/// Frees the specified storage medium.
/// Pointer to the storage medium that is to be freed.
[DllImport(Lib.Ole32, ExactSpelling = true)]
[PInvokeData("Ole2.h", MSDNShortId = "ms693491")]
public static extern void ReleaseStgMedium(in STGMEDIUM pMedium);
/// Revokes the registration of the specified application window as a potential target for OLE drag-and-drop operations.
/// Handle to a window previously registered as a target for an OLE drag-and-drop operation.
///
/// This function returns S_OK on success. Other possible values include the following.
///
///
/// Return code
/// Description
///
/// -
/// DRAGDROP_E_NOTREGISTERED
/// An attempt was made to revoke a drop target that has not been registered.
///
/// -
/// DRAGDROP_E_INVALIDHWND
/// Invalid handle returned in the hwnd parameter.
///
/// -
/// E_OUTOFMEMORY
/// There is insufficient memory for the operation.
///
///
///
///
///
/// When your application window is no longer available as a potential target for an OLE drag-and-drop operation, you must call RevokeDragDrop.
///
/// This function calls the IUnknown::Release method for your drop target interface.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-revokedragdrop HRESULT RevokeDragDrop( IN HWND hwnd );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "c0fa963c-ed06-426c-8ffc-31b02f083a23")]
public static extern HRESULT RevokeDragDrop([In] HWND hwnd);
///
/// The SetConvertStg function sets the convert bit in a storage object to indicate that the object is to be converted to a
/// new class when it is opened. The setting can be retrieved with a call to the GetConvertStg function.
///
/// IStorage pointer to the storage object in which to set the conversion bit.
///
/// If TRUE, sets the conversion bit for the object to indicate the object is to be converted when opened. If FALSE,
/// clears the conversion bit.
///
///
/// See the IStorage::CreateStream, IStorage::OpenStream, ISequentialStream::Read, and ISequentialStream::Write methods for possible
/// storage and stream access errors.
///
///
///
/// The SetConvertStg function determines the status of the convert bit in a contained object. It is called by both the
/// container application and the server in the process of converting an object from one class to another. When a user specifies
/// through a Convert To dialog (which the container produces with a call to the OleUIConvert function) that an object is to
/// be converted, the container must take the following steps:
///
///
/// -
/// Unload the object if it is currently loaded.
///
/// -
/// Call WriteClassStg to write the new CLSID to the object storage.
///
/// -
/// Call WriteFmtUserTypeStg to write the new user-type name and the existing main format to the storage.
///
/// -
///
/// Call SetConvertStg with the fConvert parameter set to TRUE to indicate that the object has been tagged for
/// conversion to a new class the next time it is loaded.
///
///
/// -
///
/// Just before the object is loaded, call OleDoAutoConvert to handle any needed object conversion, unless you call OleLoad, which
/// calls it internally.
///
///
///
///
/// When an object is initialized from a storage object and the server is the destination of a convert-to operation, the object
/// server should do the following:
///
///
/// -
/// Call the GetConvertStg function to retrieve the value of the conversion bit.
///
/// -
/// If the bit is set, the server reads the data out of the object according to the format associated with the new CLSID.
///
/// -
///
/// When the object is asked to save itself, the object should call the WriteFmtUserTypeStg function using the normal native format
/// and user type of the object.
///
///
/// -
///
/// The object should then call SetConvertStg with the fConvert parameter set to FALSE to reset the object's conversion bit.
///
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-setconvertstg HRESULT SetConvertStg( IN LPSTORAGE pStg, IN BOOL
// fConvert );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "98c8fd20-6384-4656-941c-1f24d9a4d4a9")]
public static extern HRESULT SetConvertStg([In] IStorage pStg, [MarshalAs(UnmanagedType.Bool)] bool fConvert);
/// The WriteFmtUserTypeStg function writes a clipboard format and user type to the storage object.
/// IStorage pointer to the storage object where the information is to be written.
///
/// Specifies the clipboard format that describes the structure of the native area of the storage object. The format tag includes the
/// policy for the names of streams and substorages within this storage object and the rules for interpreting data within those streams.
///
///
/// Pointer to a null-terminated Unicode string that specifies the object's current user type. The user type value, itself, cannot be
/// NULL. This is the type returned by the IOleObject::GetUserType method. If this function is transported to a remote machine
/// where the object class does not exist, this persistently stored user type can be shown to the user in dialog boxes.
///
/// This function returns HRESULT.
///
///
/// The WriteFmtUserTypeStg function must be called in an object's implementation of the IPersistStorage::Save method. It must
/// also be called by document-level objects that use structured storage for their persistent representation in their save sequence.
///
/// To read the information saved, applications call the ReadFmtUserTypeStg function.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-writefmtusertypestg HRESULT WriteFmtUserTypeStg( IN LPSTORAGE
// pstg, IN CLIPFORMAT cf, LPOLESTR lpszUserType );
[DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ole2.h", MSDNShortId = "ef60493c-164e-4633-a248-05c4afade937")]
public static extern HRESULT WriteFmtUserTypeStg([In] IStorage pstg, CLIPFORMAT cf, [MarshalAs(UnmanagedType.LPWStr)] string lpszUserType);
/// Provides a handle to a menu descriptor.
[StructLayout(LayoutKind.Sequential)]
public struct HOLEMENU : IHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HOLEMENU(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HOLEMENU NULL => new HOLEMENU(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HOLEMENU h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HOLEMENU(IntPtr h) => new HOLEMENU(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HOLEMENU h1, HOLEMENU h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HOLEMENU h1, HOLEMENU h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HOLEMENU h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to an OLE 1 stream.
[PInvokeData("ole2.h")]
[StructLayout(LayoutKind.Sequential)]
public struct OLESTREAM
{
/// A pointer to an OLESTREAMVTBL instance.
public IntPtr lpstbl;
}
}
}