diff --git a/PInvoke/Ole/Ole32/ObjBase.cs b/PInvoke/Ole/Ole32/ObjBase.cs
index 413b1456..24e0c781 100644
--- a/PInvoke/Ole/Ole32/ObjBase.cs
+++ b/PInvoke/Ole/Ole32/ObjBase.cs
@@ -746,319 +746,6 @@ namespace Vanara.PInvoke
[PInvokeData("objbase.h", MSDNShortId = "65d9cf7d-cc8a-4199-9a4a-7fd67ef8872d")]
public static extern HRESULT GetRunningObjectTable([Optional] uint reserved, out IRunningObjectTable pprot);
- ///
- /// The StgCreateStorageEx function creates a new storage object using a provided implementation for the IStorage or
- /// IPropertySetStorage interfaces. To open an existing file, use the StgOpenStorageEx function instead.
- ///
- /// Applications written for Windows 2000, Windows Server 2003 and Windows XP must use StgCreateStorageEx rather than
- /// StgCreateDocfile to take advantage of the enhanced Windows 2000 and Windows XP Structured Storage features.
- ///
- ///
- ///
- /// A pointer to the path of the file to create. It is passed uninterpreted to the file system. This can be a relative name or NULL.
- /// If NULL, a temporary file is allocated with a unique name. If non-NULL, the string size must not exceed MAX_PATH characters.
- /// Windows 2000: Unlike the CreateFile function, you cannot exceed the MAX_PATH limit by using the "\\?\" prefix.
- ///
- ///
- /// A value that specifies the access mode to use when opening the new storage object. For more information, see STGM Constants. If
- /// the caller specifies transacted mode together with STGM_CREATE or STGM_CONVERT, the overwrite or conversion takes place when the
- /// commit operation is called for the root storage. If IStorage::Commit is not called for the root storage object, previous contents
- /// of the file will be restored. STGM_CREATE and STGM_CONVERT cannot be combined with the STGM_NOSNAPSHOT flag, because a snapshot
- /// copy is required when a file is overwritten or converted in the transacted mode.
- ///
- /// A value that specifies the storage file format. For more information, see the STGFMT enumeration.
- ///
- /// A value that depends on the value of the stgfmt parameter.
- ///
- ///
- /// Parameter Values
- /// Meaning
- ///
- /// -
- /// STGFMT_DOCFILE
- ///
- /// 0, or FILE_FLAG_NO_BUFFERING.For more information, see CreateFile.If the sector size of the file, specified in pStgOptions, is
- /// not an integer multiple of the underlying disk's physical sector size, this operation will fail.
- ///
- ///
- /// -
- /// All other values of stgfmt
- /// Must be 0.
- ///
- ///
- ///
- ///
- /// The pStgOptions parameter is valid only if the stgfmt parameter is set to STGFMT_DOCFILE. If the stgfmt parameter is set to
- /// STGFMT_DOCFILE, pStgOptions points to the STGOPTIONS structure, which specifies features of the storage object, such as the
- /// sector size. This parameter may be NULL, which creates a storage object with a default sector size of 512 bytes. If non-NULL, the
- /// ulSectorSize member must be set to either 512 or 4096. If set to 4096, STGM_SIMPLE may not be specified in the grfMode parameter.
- /// The usVersion member must be set before calling StgCreateStorageEx. For more information, see STGOPTIONS.
- ///
- ///
- /// Enables the ACLs to be set when the file is created. If not NULL, needs to be a pointer to the SECURITY_ATTRIBUTES structure. See
- /// CreateFile for information on how to set ACLs on files.
- /// Windows Server 2003, Windows 2000 Server, Windows XP and Windows 2000 Professional: Value must be NULL.
- ///
- ///
- /// A value that specifies the interface identifier (IID) of the interface pointer to return. This IID may be for the IStorage
- /// interface or the IPropertySetStorage interface.
- ///
- ///
- /// A pointer to an interface pointer variable that receives a pointer for an interface on the new storage object; contains NULL if
- /// operation failed.
- ///
- ///
- /// This function can also return any file system errors or system errors wrapped in an HRESULT. For more information, see Error
- /// Handling Strategies and Handling Unknown Errors.
- ///
- [DllImport(Lib.Ole32, ExactSpelling = true, SetLastError = false)]
- [PInvokeData("Objbase.h", MSDNShortId = "aa380328")]
- public static extern HRESULT StgCreateStorageEx([MarshalAs(UnmanagedType.LPWStr)] string pwcsName, STGM grfMode,
- STGFMT stgfmt, FileFlagsAndAttributes grfAttrs, [In] IntPtr pStgOptions, PSECURITY_DESCRIPTOR pSecurityDescriptor, in Guid riid,
- [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 6)] out object ppObjectOpen);
-
- ///
- /// The StgCreateStorageEx function creates a new storage object using a provided implementation for the IStorage or
- /// IPropertySetStorage interfaces. To open an existing file, use the StgOpenStorageEx function instead.
- ///
- /// Applications written for Windows 2000, Windows Server 2003 and Windows XP must use StgCreateStorageEx rather than
- /// StgCreateDocfile to take advantage of the enhanced Windows 2000 and Windows XP Structured Storage features.
- ///
- ///
- ///
- /// A pointer to the path of the file to create. It is passed uninterpreted to the file system. This can be a relative name or NULL.
- /// If NULL, a temporary file is allocated with a unique name. If non-NULL, the string size must not exceed MAX_PATH characters.
- /// Windows 2000: Unlike the CreateFile function, you cannot exceed the MAX_PATH limit by using the "\\?\" prefix.
- ///
- ///
- /// A value that specifies the access mode to use when opening the new storage object. For more information, see STGM Constants. If
- /// the caller specifies transacted mode together with STGM_CREATE or STGM_CONVERT, the overwrite or conversion takes place when the
- /// commit operation is called for the root storage. If IStorage::Commit is not called for the root storage object, previous contents
- /// of the file will be restored. STGM_CREATE and STGM_CONVERT cannot be combined with the STGM_NOSNAPSHOT flag, because a snapshot
- /// copy is required when a file is overwritten or converted in the transacted mode.
- ///
- /// A value that specifies the storage file format. For more information, see the STGFMT enumeration.
- ///
- /// A value that depends on the value of the stgfmt parameter.
- ///
- ///
- /// Parameter Values
- /// Meaning
- ///
- /// -
- /// STGFMT_DOCFILE
- ///
- /// 0, or FILE_FLAG_NO_BUFFERING.For more information, see CreateFile.If the sector size of the file, specified in pStgOptions, is
- /// not an integer multiple of the underlying disk's physical sector size, this operation will fail.
- ///
- ///
- /// -
- /// All other values of stgfmt
- /// Must be 0.
- ///
- ///
- ///
- ///
- /// The pStgOptions parameter is valid only if the stgfmt parameter is set to STGFMT_DOCFILE. If the stgfmt parameter is set to
- /// STGFMT_DOCFILE, pStgOptions points to the STGOPTIONS structure, which specifies features of the storage object, such as the
- /// sector size. This parameter may be NULL, which creates a storage object with a default sector size of 512 bytes. If non-NULL, the
- /// ulSectorSize member must be set to either 512 or 4096. If set to 4096, STGM_SIMPLE may not be specified in the grfMode parameter.
- /// The usVersion member must be set before calling StgCreateStorageEx. For more information, see STGOPTIONS.
- ///
- ///
- /// Enables the ACLs to be set when the file is created. If not NULL, needs to be a pointer to the SECURITY_ATTRIBUTES structure. See
- /// CreateFile for information on how to set ACLs on files.
- /// Windows Server 2003, Windows 2000 Server, Windows XP and Windows 2000 Professional: Value must be NULL.
- ///
- ///
- /// A value that specifies the interface identifier (IID) of the interface pointer to return. This IID may be for the IStorage
- /// interface or the IPropertySetStorage interface.
- ///
- ///
- /// A pointer to an interface pointer variable that receives a pointer for an interface on the new storage object; contains NULL if
- /// operation failed.
- ///
- ///
- /// This function can also return any file system errors or system errors wrapped in an HRESULT. For more information, see Error
- /// Handling Strategies and Handling Unknown Errors.
- ///
- [DllImport(Lib.Ole32, ExactSpelling = true, SetLastError = false)]
- [PInvokeData("Objbase.h", MSDNShortId = "aa380328")]
- public static extern HRESULT StgCreateStorageEx([MarshalAs(UnmanagedType.LPWStr)] string pwcsName, STGM grfMode,
- STGFMT stgfmt, FileFlagsAndAttributes grfAttrs, in STGOPTIONS pStgOptions, PSECURITY_DESCRIPTOR pSecurityDescriptor, in Guid riid,
- [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 6)] out object ppObjectOpen);
-
- /// The StgIsStorageFile function indicates whether a particular disk file contains a storage object.
- ///
- /// Pointer to the null-terminated Unicode string name of the disk file to be examined. The pwcsName parameter is passed
- /// uninterpreted to the underlying file system.
- ///
- ///
- ///
- /// -
- /// S_OK
- /// Indicates that the file contains a storage object.
- ///
- /// -
- /// S_FALSE
- /// Indicates that the file does not contain a storage object.
- ///
- /// -
- /// STG_E_FILENOTFOUND
- /// Indicates that the file was not found.
- ///
- ///
- ///
- /// StgIsStorageFile function can also return any file system errors or system errors wrapped in an HRESULT. See Error Handling
- /// Strategies and Handling Unknown Errors
- ///
- ///
- [DllImport(Lib.Ole32, ExactSpelling = true, SetLastError = false)]
- [PInvokeData("Objbase.h", MSDNShortId = "aa380334")]
- public static extern HRESULT StgIsStorageFile([MarshalAs(UnmanagedType.LPWStr)] string pwcsName);
-
- ///
- /// The StgOpenStorage function opens an existing root storage object in the file system. Use this function to open compound files.
- /// Do not use it to open directories, files, or summary catalogs. Nested storage objects can only be opened using their parent
- /// IStorage::OpenStorage method. Applications should use the new function, StgOpenStorageEx, instead of
- /// StgOpenStorage, to take advantage of the enhanced and Windows Structured Storage features. This function, StgOpenStorage, still
- /// exists for compatibility with applications running on Windows 2000.
- ///
- ///
- /// A pointer to the path of the null-terminated Unicode string file that contains the storage object to open. This parameter is
- /// ignored if the pstgPriority parameter is not NULL.
- ///
- ///
- /// A pointer to the IStorage interface that should be NULL. If not NULL, this parameter is used as described below in the Remarks
- /// section. After StgOpenStorage returns, the storage object specified in pStgPriority may have been released and should no longer
- /// be used.
- ///
- /// Specifies the access mode to use to open the storage object.
- ///
- /// If not NULL, pointer to a block of elements in the storage to be excluded as the storage object is opened. The exclusion occurs
- /// regardless of whether a snapshot copy happens on the open. Can be NULL.
- ///
- /// Indicates reserved for future use; must be zero.
- /// A pointer to a IStorage* pointer variable that receives the interface pointer to the opened storage.
- ///
- /// The StgOpenStorage function can also return any file system errors or system errors wrapped in an HRESULT. For more information,
- /// see Error Handling Strategies and Handling Unknown Errors.
- ///
- [DllImport(Lib.Ole32, ExactSpelling = true, SetLastError = false)]
- [PInvokeData("Objbase.h", MSDNShortId = "aa380341")]
- public static extern HRESULT StgOpenStorage([MarshalAs(UnmanagedType.LPWStr)] string pwcsName,
- IStorage pstgPriority, STGM grfMode, [In] SNB snbExclude, [Optional] uint reserved, out IStorage ppstgOpen);
-
- /// STGs the open storage ex.
- ///
- /// A pointer to the path of the null-terminated Unicode string file that contains the storage object. This string size cannot exceed
- /// MAX_PATH characters.
- ///
- /// Windows Server 2003 and Windows XP/2000: Unlike the CreateFile function, the MAX_PATH limit cannot be exceeded by using the
- /// "\\?\" prefix.
- ///
- ///
- ///
- /// A value that specifies the access mode to open the new storage object. For more information, see STGM Constants. If the caller
- /// specifies transacted mode together with STGM_CREATE or STGM_CONVERT, the overwrite or conversion occurs when the commit operation
- /// is called for the root storage. If IStorage::Commit is not called for the root storage object, previous contents of the file will
- /// be restored. STGM_CREATE and STGM_CONVERT cannot be combined with the STGM_NOSNAPSHOT flag, because a snapshot copy is required
- /// when a file is overwritten or converted in transacted mode.
- ///
- /// If the storage object is opened in direct mode(STGM_DIRECT) with access to either STGM_WRITE or STGM_READWRITE, the sharing mode
- /// must be STGM_SHARE_EXCLUSIVE unless the STGM_DIRECT_SWMR mode is specified.For more information, see the Remarks section.If the
- /// storage object is opened in direct mode with access to STGM_READ, the sharing mode must be either STGM_SHARE_EXCLUSIVE or
- /// STGM_SHARE_DENY_WRITE, unless STGM_PRIORITY or STGM_DIRECT_SWMR is specified.For more information, see the Remarks section.
- ///
- ///
- /// The mode in which a file is opened can affect implementation performance.For more information, see Compound File Implementation Limits.
- ///
- ///
- /// A value that specifies the storage file format. For more information, see the STGFMT enumeration.
- ///
- /// A value that depends upon the value of the stgfmt parameter. STGFMT_DOCFILE must be zero (0) or FILE_FLAG_NO_BUFFERING. For more
- /// information about this value, see CreateFile. If the sector size of the file, specified in pStgOptions, is not an integer
- /// multiple of the physical sector size of the underlying disk, then this operation will fail. All other values of stgfmt must be zero.
- ///
- ///
- /// A pointer to an STGOPTIONS structure that contains data about the storage object opened. The pStgOptions parameter is valid only
- /// if the stgfmt parameter is set to STGFMT_DOCFILE. The usVersion member must be set before calling StgOpenStorageEx. For more
- /// information, see the STGOPTIONS structure.
- ///
- /// Reserved; must be zero.
- ///
- /// A value that specifies the GUID of the interface pointer to return. Can also be the header-specified value for IID_IStorage to
- /// obtain the IStorage interface or for IID_IPropertySetStorage to obtain the IPropertySetStorage interface.
- ///
- ///
- /// The address of an interface pointer variable that receives a pointer for an interface on the storage object opened; contains NULL
- /// if operation failed.
- ///
- ///
- /// This function can also return any file system errors or system errors wrapped in an HRESULT. For more information, see Error
- /// Handling Strategies and Handling Unknown Errors.
- ///
- [DllImport(Lib.Ole32, ExactSpelling = true, SetLastError = false)]
- [PInvokeData("Objbase.h", MSDNShortId = "aa380342")]
- public static extern HRESULT StgOpenStorageEx([MarshalAs(UnmanagedType.LPWStr)] string pwcsName, STGM grfMode, STGFMT stgfmt,
- FileFlagsAndAttributes grfAttrs, ref STGOPTIONS pStgOptions, [Optional] IntPtr reserved2, in Guid riid,
- [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 6)] out object ppObjectOpen);
-
- /// STGs the open storage ex.
- ///
- /// A pointer to the path of the null-terminated Unicode string file that contains the storage object. This string size cannot exceed
- /// MAX_PATH characters.
- ///
- /// Windows Server 2003 and Windows XP/2000: Unlike the CreateFile function, the MAX_PATH limit cannot be exceeded by using the
- /// "\\?\" prefix.
- ///
- ///
- ///
- /// A value that specifies the access mode to open the new storage object. For more information, see STGM Constants. If the caller
- /// specifies transacted mode together with STGM_CREATE or STGM_CONVERT, the overwrite or conversion occurs when the commit operation
- /// is called for the root storage. If IStorage::Commit is not called for the root storage object, previous contents of the file will
- /// be restored. STGM_CREATE and STGM_CONVERT cannot be combined with the STGM_NOSNAPSHOT flag, because a snapshot copy is required
- /// when a file is overwritten or converted in transacted mode.
- ///
- /// If the storage object is opened in direct mode(STGM_DIRECT) with access to either STGM_WRITE or STGM_READWRITE, the sharing mode
- /// must be STGM_SHARE_EXCLUSIVE unless the STGM_DIRECT_SWMR mode is specified.For more information, see the Remarks section.If the
- /// storage object is opened in direct mode with access to STGM_READ, the sharing mode must be either STGM_SHARE_EXCLUSIVE or
- /// STGM_SHARE_DENY_WRITE, unless STGM_PRIORITY or STGM_DIRECT_SWMR is specified.For more information, see the Remarks section.
- ///
- ///
- /// The mode in which a file is opened can affect implementation performance.For more information, see Compound File Implementation Limits.
- ///
- ///
- /// A value that specifies the storage file format. For more information, see the STGFMT enumeration.
- ///
- /// A value that depends upon the value of the stgfmt parameter. STGFMT_DOCFILE must be zero (0) or FILE_FLAG_NO_BUFFERING. For more
- /// information about this value, see CreateFile. If the sector size of the file, specified in pStgOptions, is not an integer
- /// multiple of the physical sector size of the underlying disk, then this operation will fail. All other values of stgfmt must be zero.
- ///
- ///
- /// A pointer to an STGOPTIONS structure that contains data about the storage object opened. The pStgOptions parameter is valid only
- /// if the stgfmt parameter is set to STGFMT_DOCFILE. The usVersion member must be set before calling StgOpenStorageEx. For more
- /// information, see the STGOPTIONS structure.
- ///
- /// Reserved; must be zero.
- ///
- /// A value that specifies the GUID of the interface pointer to return. Can also be the header-specified value for IID_IStorage to
- /// obtain the IStorage interface or for IID_IPropertySetStorage to obtain the IPropertySetStorage interface.
- ///
- ///
- /// The address of an interface pointer variable that receives a pointer for an interface on the storage object opened; contains NULL
- /// if operation failed.
- ///
- ///
- /// This function can also return any file system errors or system errors wrapped in an HRESULT. For more information, see Error
- /// Handling Strategies and Handling Unknown Errors.
- ///
- [DllImport(Lib.Ole32, ExactSpelling = true, SetLastError = false)]
- [PInvokeData("Objbase.h", MSDNShortId = "aa380342")]
- public static extern HRESULT StgOpenStorageEx([MarshalAs(UnmanagedType.LPWStr)] string pwcsName, STGM grfMode, STGFMT stgfmt,
- FileFlagsAndAttributes grfAttrs, [Optional] IntPtr pStgOptions, [Optional] IntPtr reserved2, in Guid riid,
- [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 6)] out object ppObjectOpen);
-
/// Provides a CO_MTA_USAGE_COOKIE.
[StructLayout(LayoutKind.Sequential)]
public struct CO_MTA_USAGE_COOKIE : IHandle
diff --git a/PInvoke/Ole/Ole32/coml2api.cs b/PInvoke/Ole/Ole32/coml2api.cs
new file mode 100644
index 00000000..ae45609c
--- /dev/null
+++ b/PInvoke/Ole/Ole32/coml2api.cs
@@ -0,0 +1,1521 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Runtime.InteropServices.ComTypes;
+using System.Text;
+using Vanara.InteropServices;
+using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
+using STATSTG = System.Runtime.InteropServices.ComTypes.STATSTG;
+
+namespace Vanara.PInvoke
+{
+ public static partial class Ole32
+ {
+ ///
+ ///
+ /// The CreateILockBytesOnHGlobal function creates a byte array object that uses an HGLOBAL memory handle to store the bytes
+ /// intended for in-memory storage of a compound file. This object is the OLE-provided implementation of the ILockBytes interface.
+ ///
+ ///
+ /// The returned byte array object supports both reading and writing, but does not support region locking . The object calls the
+ /// GlobalReAlloc function to grow the memory block as required.
+ ///
+ ///
+ ///
+ /// A memory handle allocated by the GlobalAlloc function, or if NULL a new handle is to be allocated instead. The handle must
+ /// be allocated as moveable and nondiscardable.
+ ///
+ ///
+ /// A flag that specifies whether the underlying handle for this byte array object should be automatically freed when the object is
+ /// released. If set to FALSE, the caller must free the hGlobal after the final release. If set to TRUE, the final
+ /// release will automatically free the hGlobal parameter.
+ ///
+ ///
+ /// The address of ILockBytes pointer variable that receives the interface pointer to the new byte array object.
+ ///
+ /// This function supports the standard return values E_INVALIDARG and E_OUTOFMEMORY, as well as the following:
+ ///
+ ///
+ /// If hGlobal is NULL, the CreateILockBytesOnHGlobal allocates a new memory handle and the byte array is empty initially.
+ ///
+ ///
+ /// If hGlobal is not NULL, the initial contents of the byte array object are the current contents of the memory block. Thus,
+ /// this function can be used to open an existing byte array in memory, for example to reload a storage object previously created by
+ /// the StgCreateDocfileOnILockBytes function. The memory handle and its contents are undisturbed by the creation of the new byte
+ /// array object.
+ ///
+ ///
+ /// The initial size of the byte array is the size of hGlobal as returned by the GlobalSize function. This is not necessarily the
+ /// same size that was originally allocated for the handle because of rounding. If the logical size of the byte array is important,
+ /// follow the call to CreateILockBytesOnHGlobal with a call to ILockBytes::SetSize.
+ ///
+ ///
+ /// After creating the byte array object with CreateStreamOnHGlobal, StgCreateDocfileOnILockBytes can be used to create a new storage
+ /// object in memory, or StgOpenStorageOnILockBytes can be used to reopen a previously existing storage object that is already
+ /// contained in the memory block. GetHGlobalFromILockBytes can be called to retrieve the memory handle associated with the byte
+ /// array object.
+ ///
+ ///
+ /// If a memory handle is passed to CreateILockBytesOnHGlobal or if GetHGlobalFromILockBytes is called, the memory handle of
+ /// this function can be directly accessed by the caller while it is still in use by the byte array object. Appropriate caution
+ /// should be exercised in the use of this capability and its implications:
+ ///
+ ///
+ /// -
+ ///
+ /// Do not free the hGlobal memory handle during the lifetime of the byte array object. ILockBytes::Releasemust be called before the
+ /// memory handle is freed.
+ ///
+ ///
+ /// -
+ ///
+ /// Do not call GlobalReAlloc to change the size of the memory handle during the lifetime of the byte array object. This may cause
+ /// application crashes or memory corruption. Avoid creating multiple byte array objects on the same memory handle, because
+ /// ILockBytes::WriteAt and ILockBytes::SetSize methods may internally call GlobalReAlloc.
+ ///
+ ///
+ /// -
+ ///
+ /// If possible, avoid accessing the memory block during the lifetime of the byte array object, because the object may internally
+ /// call GlobalReAlloc and do not make assumptions about its size and location. If the memory block must be accessed, the memory
+ /// access calls should be surrounded by calls to GlobalLock and GlobalUnLock.
+ ///
+ ///
+ /// -
+ ///
+ /// Avoid calling the object’s methods while the memory handle is locked with GlobalLock. This can cause method calls to fail unpredictably.
+ ///
+ ///
+ ///
+ ///
+ /// If the caller sets the fDeleteOnRelease parameter to FALSE, then the caller must also free the hGlobal after the final
+ /// release. If the caller sets the fDeleteOnRelease parameter to TRUE, the final release will automatically free the hGlobal.
+ /// The memory handle passed as the hGlobal parameter must be allocated as movable and nondiscardable, as shown in the following example:
+ ///
+ ///
+ /// CreateILockBytesOnHGlobal will accept memory allocated with GMEM_FIXED, but this usage is not recommended. HGLOBALs
+ /// allocated with GMEM_FIXED are not really handles and their value can change when they are reallocated. If the memory
+ /// handle was allocated with GMEM_FIXED and fDeleteOnRelease is FALSE, then the caller must call
+ /// GetHGlobalFromILockBytes to get the correct HGLOBAL value in order to free the handle.
+ ///
+ ///
+ /// This implementation of ILockBytes does not support region locking. Applications that use this implementation with the
+ /// StgCreateDocfileOnILockBytes or StgOpenStorageOnILockBytes functions should avoid opening multiple concurrent instances on the
+ /// same ILockBytes object.
+ ///
+ ///
+ /// Prior to Windows 7 and Windows Server 2008 R2, this implementation did not zero memory when calling GlobalReAlloc to grow the
+ /// memory block. Increasing the size of the byte array with ILockBytes::SetSize or by writing to a location past the current end of
+ /// the byte array will leave any unwritten portions of the newly allocated memory uninitialized. The storage objects returned by the
+ /// StgCreateDocfileOnILockBytes and StgOpenStorageOnILockBytes may increase the size of the byte array without initializing all of
+ /// the newly allocated space.
+ ///
+ ///
+ /// Compound files in memory are typically used as scratch space or with APIs that require a storage object, and in these cases the
+ /// uninitialized memory is generally not a concern. However, if the contents of the memory block will be written to a file, consider
+ /// the following alternatives to avoid potential information disclosure:
+ ///
+ ///
+ /// -
+ ///
+ /// Copy the logical contents of the in-memory compound file to the destination file using the IStorage::CopyTo method rather than
+ /// directly writing the contents of the memory block.
+ ///
+ ///
+ /// -
+ ///
+ /// Instead of a compound file in memory, create a temporary file by calling StgCreateStorageEx with a NULL value for the
+ /// pwcsName parameter. When it is time to write to the destination file, use the IRootStorage::SwitchToFile method.
+ ///
+ ///
+ /// -
+ ///
+ /// Implement the ILockBytes interface such that memory reallocations are zeroed (see for example the HEAP_ZERO_MEMORY flag in
+ /// HeapReAlloc). The memory contents of this byte array can then be written to a file.
+ ///
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-createilockbytesonhglobal HRESULT
+ // CreateILockBytesOnHGlobal( HGLOBAL hGlobal, BOOL fDeleteOnRelease, LPLOCKBYTES *pplkbyt );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "e7963be7-ccd8-49fb-85bb-e22fbbb6dc5c")]
+ public static extern HRESULT CreateILockBytesOnHGlobal([Optional] IntPtr hGlobal, [MarshalAs(UnmanagedType.Bool)] bool fDeleteOnRelease, out ILockBytes pplkbyt);
+
+ ///
+ ///
+ /// The CreateILockBytesOnHGlobal function creates a byte array object that uses an HGLOBAL memory handle to store the bytes
+ /// intended for in-memory storage of a compound file. This object is the OLE-provided implementation of the ILockBytes interface.
+ ///
+ ///
+ /// The returned byte array object supports both reading and writing, but does not support region locking . The object calls the
+ /// GlobalReAlloc function to grow the memory block as required.
+ ///
+ ///
+ ///
+ /// A memory handle allocated by the GlobalAlloc function, or if NULL a new handle is to be allocated instead. The handle must
+ /// be allocated as moveable and nondiscardable.
+ ///
+ ///
+ /// A flag that specifies whether the underlying handle for this byte array object should be automatically freed when the object is
+ /// released. If set to FALSE, the caller must free the hGlobal after the final release. If set to TRUE, the final
+ /// release will automatically free the hGlobal parameter.
+ ///
+ ///
+ /// The address of ILockBytes pointer variable that receives the interface pointer to the new byte array object.
+ ///
+ /// This function supports the standard return values E_INVALIDARG and E_OUTOFMEMORY, as well as the following:
+ ///
+ ///
+ /// If hGlobal is NULL, the CreateILockBytesOnHGlobal allocates a new memory handle and the byte array is empty initially.
+ ///
+ ///
+ /// If hGlobal is not NULL, the initial contents of the byte array object are the current contents of the memory block. Thus,
+ /// this function can be used to open an existing byte array in memory, for example to reload a storage object previously created by
+ /// the StgCreateDocfileOnILockBytes function. The memory handle and its contents are undisturbed by the creation of the new byte
+ /// array object.
+ ///
+ ///
+ /// The initial size of the byte array is the size of hGlobal as returned by the GlobalSize function. This is not necessarily the
+ /// same size that was originally allocated for the handle because of rounding. If the logical size of the byte array is important,
+ /// follow the call to CreateILockBytesOnHGlobal with a call to ILockBytes::SetSize.
+ ///
+ ///
+ /// After creating the byte array object with CreateStreamOnHGlobal, StgCreateDocfileOnILockBytes can be used to create a new storage
+ /// object in memory, or StgOpenStorageOnILockBytes can be used to reopen a previously existing storage object that is already
+ /// contained in the memory block. GetHGlobalFromILockBytes can be called to retrieve the memory handle associated with the byte
+ /// array object.
+ ///
+ ///
+ /// If a memory handle is passed to CreateILockBytesOnHGlobal or if GetHGlobalFromILockBytes is called, the memory handle of
+ /// this function can be directly accessed by the caller while it is still in use by the byte array object. Appropriate caution
+ /// should be exercised in the use of this capability and its implications:
+ ///
+ ///
+ /// -
+ ///
+ /// Do not free the hGlobal memory handle during the lifetime of the byte array object. ILockBytes::Releasemust be called before the
+ /// memory handle is freed.
+ ///
+ ///
+ /// -
+ ///
+ /// Do not call GlobalReAlloc to change the size of the memory handle during the lifetime of the byte array object. This may cause
+ /// application crashes or memory corruption. Avoid creating multiple byte array objects on the same memory handle, because
+ /// ILockBytes::WriteAt and ILockBytes::SetSize methods may internally call GlobalReAlloc.
+ ///
+ ///
+ /// -
+ ///
+ /// If possible, avoid accessing the memory block during the lifetime of the byte array object, because the object may internally
+ /// call GlobalReAlloc and do not make assumptions about its size and location. If the memory block must be accessed, the memory
+ /// access calls should be surrounded by calls to GlobalLock and GlobalUnLock.
+ ///
+ ///
+ /// -
+ ///
+ /// Avoid calling the object’s methods while the memory handle is locked with GlobalLock. This can cause method calls to fail unpredictably.
+ ///
+ ///
+ ///
+ ///
+ /// If the caller sets the fDeleteOnRelease parameter to FALSE, then the caller must also free the hGlobal after the final
+ /// release. If the caller sets the fDeleteOnRelease parameter to TRUE, the final release will automatically free the hGlobal.
+ /// The memory handle passed as the hGlobal parameter must be allocated as movable and nondiscardable, as shown in the following example:
+ ///
+ ///
+ /// CreateILockBytesOnHGlobal will accept memory allocated with GMEM_FIXED, but this usage is not recommended. HGLOBALs
+ /// allocated with GMEM_FIXED are not really handles and their value can change when they are reallocated. If the memory
+ /// handle was allocated with GMEM_FIXED and fDeleteOnRelease is FALSE, then the caller must call
+ /// GetHGlobalFromILockBytes to get the correct HGLOBAL value in order to free the handle.
+ ///
+ ///
+ /// This implementation of ILockBytes does not support region locking. Applications that use this implementation with the
+ /// StgCreateDocfileOnILockBytes or StgOpenStorageOnILockBytes functions should avoid opening multiple concurrent instances on the
+ /// same ILockBytes object.
+ ///
+ ///
+ /// Prior to Windows 7 and Windows Server 2008 R2, this implementation did not zero memory when calling GlobalReAlloc to grow the
+ /// memory block. Increasing the size of the byte array with ILockBytes::SetSize or by writing to a location past the current end of
+ /// the byte array will leave any unwritten portions of the newly allocated memory uninitialized. The storage objects returned by the
+ /// StgCreateDocfileOnILockBytes and StgOpenStorageOnILockBytes may increase the size of the byte array without initializing all of
+ /// the newly allocated space.
+ ///
+ ///
+ /// Compound files in memory are typically used as scratch space or with APIs that require a storage object, and in these cases the
+ /// uninitialized memory is generally not a concern. However, if the contents of the memory block will be written to a file, consider
+ /// the following alternatives to avoid potential information disclosure:
+ ///
+ ///
+ /// -
+ ///
+ /// Copy the logical contents of the in-memory compound file to the destination file using the IStorage::CopyTo method rather than
+ /// directly writing the contents of the memory block.
+ ///
+ ///
+ /// -
+ ///
+ /// Instead of a compound file in memory, create a temporary file by calling StgCreateStorageEx with a NULL value for the
+ /// pwcsName parameter. When it is time to write to the destination file, use the IRootStorage::SwitchToFile method.
+ ///
+ ///
+ /// -
+ ///
+ /// Implement the ILockBytes interface such that memory reallocations are zeroed (see for example the HEAP_ZERO_MEMORY flag in
+ /// HeapReAlloc). The memory contents of this byte array can then be written to a file.
+ ///
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-createilockbytesonhglobal HRESULT
+ // CreateILockBytesOnHGlobal( HGLOBAL hGlobal, BOOL fDeleteOnRelease, LPLOCKBYTES *pplkbyt );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "e7963be7-ccd8-49fb-85bb-e22fbbb6dc5c")]
+ public static extern HRESULT CreateILockBytesOnHGlobal(SafeHGlobalHandle hGlobal, [MarshalAs(UnmanagedType.Bool)] bool fDeleteOnRelease, out ILockBytes pplkbyt);
+
+ ///
+ /// The FmtIdToPropStgName function converts a property set format identifier (FMTID) to its storage or stream name.
+ ///
+ /// A pointer to the FMTID of the property set.
+ ///
+ /// A pointer to a null-terminated string that receives the storage or stream name of the property set identified by pfmtid. The
+ /// array allocated for this string must be at least CCH_MAX_PROPSTG_NAME (32) characters in length.
+ ///
+ /// This function supports the standard return value E_INVALIDARG as well as the following:
+ ///
+ ///
+ /// FmtIdToPropStgName maps a property set FMTID to its stream name for a simple property set or to its storage name for a
+ /// nonsimple property set.
+ ///
+ ///
+ /// This function is useful in creating or opening a property set using the PROPSETFLAG_UNBUFFERED value with the StgCreatePropStg
+ /// and StgOpenPropStg functions. For more information about PROPSETFLAG_UNBUFFERED, see PROPSETFLAG Constants.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-fmtidtopropstgname HRESULT FmtIdToPropStgName( const
+ // FMTID *pfmtid, LPOLESTR oszName );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "044f8883-bbd2-4cd3-b9dc-739ecb711bdd")]
+ public static extern HRESULT FmtIdToPropStgName(in Guid pfmtid, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder oszName);
+
+ /// The GetConvertStg function returns the current value of the convert bit for the specified storage object.
+ /// IStorage pointer to the storage object from which the convert bit is to be retrieved.
+ /// IStorage::OpenStream, IStorage::OpenStorage, and ISequentialStream::Read storage and stream access errors.
+ ///
+ ///
+ /// The GetConvertStg function is called by object servers that support the conversion of an object from one format to
+ /// another. The server must be able to read the storage object using the format of its previous class identifier (CLSID) and write
+ /// the object using the format of its new CLSID to support the object's conversion. For example, a spreadsheet created by one
+ /// application can be converted to the format used by a different application.
+ ///
+ ///
+ /// The convert bit is set by a call to the SetConvertStg function. A container application can call this function on the request of
+ /// an end user, or a setup program can call it when installing a new version of an application. An end user requests converting an
+ /// object through the Convert To dialog box. When an object is converted, the new CLSID is permanently assigned to the
+ /// object, so the object is subsequently associated with the new CLSID.
+ ///
+ ///
+ /// Then, when the object is activated, its server calls the GetConvertStg function to retrieve the value of the convert bit
+ /// from the storage object. If the bit is set, the object's CLSID has been changed, and the server must read the old format and
+ /// write the new format for the storage object.
+ ///
+ ///
+ /// After retrieving the bit value, the object application should clear the convert bit by calling the SetConvertStg function with
+ /// its fConvert parameter set to FALSE.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-getconvertstg HRESULT GetConvertStg( LPSTORAGE pStg );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "748649a2-cf75-4ffa-ac1f-4a148b845d21")]
+ public static extern HRESULT GetConvertStg(IStorage pStg);
+
+ ///
+ /// The GetHGlobalFromILockBytes function retrieves a global memory handle to a byte array object created using the
+ /// CreateILockBytesOnHGlobal function.
+ ///
+ ///
+ /// Pointer to the ILockBytes interface on the byte-array object previously created by a call to the CreateILockBytesOnHGlobal function.
+ ///
+ /// Pointer to the current memory handle used by the specified byte-array object.
+ /// This function returns HRESULT.
+ ///
+ ///
+ /// After a call to CreateILockBytesOnHGlobal, which creates a byte array object on global memory, GetHGlobalFromILockBytes
+ /// retrieves a pointer to the handle of the global memory underlying the byte array object. The handle this function returns might
+ /// be different from the original handle due to intervening calls to the GlobalReAlloc function.
+ ///
+ ///
+ /// The contents of the returned memory handle can be written to a clean disk file, and then opened as a storage object using the
+ /// StgOpenStorage function.
+ ///
+ /// This function only works within the same process from which the byte array was created.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-gethglobalfromilockbytes HRESULT
+ // GetHGlobalFromILockBytes( LPLOCKBYTES plkbyt, HGLOBAL *phglobal );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "084fcd1d-5b85-448c-862a-378353e1e2e6")]
+ public static extern HRESULT GetHGlobalFromILockBytes([In] ILockBytes plkbyt, out IntPtr phglobal);
+
+ /// The PropStgNameToFmtId function converts a property set storage or stream name to its format identifier.
+ ///
+ /// A pointer to a null-terminated Unicode string that contains the stream name of a simple property set or the storage name of a
+ /// nonsimple property set.
+ ///
+ /// A pointer to a FMTID variable that receives the format identifier of the property set specified by oszName.
+ /// This function supports the standard return value E_INVALIDARG as well as the following:
+ ///
+ ///
+ /// The PropStgNameToFmtId function maps the stream name of a simple property set or the storage name of a nonsimple property
+ /// set to its format identifier.
+ ///
+ ///
+ /// This function is useful in creating or opening a property set using the PROPSETFLAG_UNBUFFERED value with the StgCreatePropStg
+ /// and StgOpenPropStg functions. For more information about PROPSETFLAG_UNBUFFERED, see PROPSETFLAG Constants.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-propstgnametofmtid HRESULT PropStgNameToFmtId( const
+ // LPOLESTR oszName, FMTID *pfmtid );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "bbbaf5a3-df17-42fd-ba2b-ad5b572c8a3f")]
+ public static extern HRESULT PropStgNameToFmtId([MarshalAs(UnmanagedType.LPWStr)] string oszName, out Guid pfmtid);
+
+ /// The ReadClassStg function reads the CLSID previously written to a storage object with the WriteClassStg function.
+ /// Pointer to the IStorage interface on the storage object containing the CLSID to be retrieved.
+ /// Pointer to where the CLSID is written. May return CLSID_NULL.
+ ///
+ /// This function supports the standard return value E_OUTOFMEMORY, in addition to the following:
+ /// This function also returns any of the error values returned by the IStorage::Stat method.
+ ///
+ ///
+ /// ReadClassStg is a helper function that calls the IStorage::Stat method and retrieves the CLSID previously written to the
+ /// storage object with a call to WriteClassStg from the STATSTG structure.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-readclassstg HRESULT ReadClassStg( LPSTORAGE pStg, CLSID
+ // *pclsid );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "90256fcd-54ce-48e1-aa12-d8f91cd4dfb1")]
+ public static extern HRESULT ReadClassStg([In] IStorage pStg, out Guid pclsid);
+
+ /// The ReadClassStm function reads the CLSID previously written to a stream object with the WriteClassStm function.
+ ///
+ /// A pointer to the IStream interface on the stream object that contains the CLSID to be read. This CLSID must have been previously
+ /// written to the stream object using WriteClassStm.
+ ///
+ /// A pointer to where the CLSID is to be written.
+ /// This function also returns any of the error values returned by the ISequentialStream::Read method.
+ ///
+ /// Most applications do not call the ReadClassStm function directly. COM calls it before making a call to an object's
+ /// IPersistStream::Load implementation.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-readclassstm HRESULT ReadClassStm( LPSTREAM pStm, CLSID
+ // *pclsid );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "bcf11c5b-e164-4a0f-b30f-ee9e76c4356d")]
+ public static extern HRESULT ReadClassStm([In] IStream pStm, out Guid pclsid);
+
+ ///
+ ///
+ /// The StgCreateDocfile function creates a new compound file storage object using the COM-provided compound file
+ /// implementation for the IStorage interface.
+ ///
+ ///
+ /// Note Applications should use the new function, StgCreateStorageEx, instead of StgCreateDocfile, to take advantage
+ /// of enhanced Structured Storage features. This function, StgCreateDocfile, still exists for compatibility with Windows 2000.
+ ///
+ ///
+ ///
+ /// A pointer to a null-terminated Unicode string name for the compound file being created. It is passed uninterpreted to the file
+ /// system. This can be a relative name or NULL. If NULL, a temporary compound file is allocated with a unique name.
+ ///
+ ///
+ /// Specifies the access mode to use when opening the new storage object. For more information, see STGM Constants. If the caller
+ /// specifies transacted mode together with STGM_CREATE or STGM_CONVERT, the overwrite or conversion takes place when the commit
+ /// operation is called for the root storage. If IStorage::Commit is not called for the root storage object, previous contents of the
+ /// file will be restored. STGM_CREATE and STGM_CONVERT cannot be combined with the STGM_NOSNAPSHOT flag, because a snapshot copy is
+ /// required when a file is overwritten or converted in the transacted mode.
+ ///
+ /// Reserved for future use; must be zero.
+ /// A pointer to the location of the IStorage pointer to the new storage object.
+ ///
+ /// StgCreateDocfile can also return any file system errors or system errors wrapped in an HRESULT. For more
+ /// information, see Error Handling Strategies and Handling Unknown Errors.
+ ///
+ ///
+ ///
+ /// The StgCreateDocfile function creates a new storage object using the COM-provided, compound-file implementation for the
+ /// IStorage interface. The name of the open compound file can be retrieved by calling the IStorage::Stat method.
+ ///
+ ///
+ /// StgCreateDocfile creates the file if it does not exist. If it does exist, the use of the STGM_CREATE, STGM_CONVERT, and
+ /// STGM_FAILIFTHERE flags in the grfMode parameter indicate how to proceed. For more information, see STGM Constants.
+ ///
+ ///
+ /// If the compound file is opened in transacted mode (the grfMode parameter specifies STGM_TRANSACTED) and a file with this name
+ /// already exists, the existing file is not altered until all outstanding changes are committed. If the calling process lacks write
+ /// access to the existing file (because of access control in the file system), the grfMode parameter can only specify STGM_READ and
+ /// not STGM_WRITE or STGM_READWRITE. The resulting new open compound file can still be written to, but a subsequent commit operation
+ /// will fail (in transacted mode, write permissions are enforced at commit time).
+ ///
+ ///
+ /// Specifying STGM_SIMPLE provides a much faster implementation of a compound file object in a limited, but frequently used case.
+ /// This can be used by applications that require a compound-file implementation with multiple streams and no storages. The simple
+ /// mode does not support all of the methods on IStorage. For more information, see STGM Constants.
+ ///
+ ///
+ /// If the grfMode parameter specifies STGM_TRANSACTED and no file yet exists with the name specified by the pwcsName parameter, the
+ /// file is created immediately. In an access-controlled file system, the caller must have write permissions in the file system
+ /// directory in which the compound file is created. If STGM_TRANSACTED is not specified, and STGM_CREATE is specified, an existing
+ /// file with the same name is destroyed before the new file is created.
+ ///
+ ///
+ /// StgCreateDocfile can be used to create a temporary compound file by passing a NULL value for the pwcsName
+ /// parameter. However, these files are temporary only in the sense that they have a system-provided unique name — likely one that is
+ /// meaningless to the user. The caller is responsible for deleting the temporary file when finished with it, unless
+ /// STGM_DELETEONRELEASE was specified for the grfMode parameter.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgcreatedocfile HRESULT StgCreateDocfile( const WCHAR
+ // *pwcsName, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "3292484b-8eff-438d-b989-b58ae323872b")]
+ public static extern HRESULT StgCreateDocfile([MarshalAs(UnmanagedType.LPWStr)] string pwcsName, STGM grfMode, [Optional] uint reserved, out IStorage ppstgOpen);
+
+ ///
+ /// The StgCreateDocfileOnILockBytes function creates and opens a new compound file storage object on top of a byte-array
+ /// object provided by the caller. The storage object supports the COM-provided, compound-file implementation for the IStorage interface.
+ ///
+ ///
+ /// A pointer to the ILockBytes interface on the underlying byte-array object on which to create a compound file.
+ ///
+ ///
+ /// Specifies the access mode to use when opening the new compound file. For more information, see STGM Constants and the Remarks
+ /// section below.
+ ///
+ /// Reserved for future use; must be zero.
+ /// A pointer to the location of the IStorage pointer on the new storage object.
+ ///
+ /// The StgCreateDocfileOnILockBytes function can also return any file system errors, or system errors wrapped in an
+ /// HRESULT, or ILockBytes interface error return values. For more information, see Error Handling Strategies and Handling
+ /// Unknown Errors.
+ ///
+ ///
+ ///
+ /// The StgCreateDocfileOnILockBytes function creates a storage object on top of a byte array object using the COM-provided,
+ /// compound-file implementation of the IStorage interface. StgCreateDocfileOnILockBytes can be used to store a document in an
+ /// arbitrary data store, such as memory or a relational database. The byte array (indicated by the pLkbyt parameter, which points to
+ /// the ILockBytes interface on the object) is used for the underlying storage in place of a disk file.
+ ///
+ ///
+ /// Except for specifying a programmer-provided byte-array object, StgCreateDocfileOnILockBytes is similar to the
+ /// StgCreateDocfile function.
+ ///
+ ///
+ /// The newly created compound file is opened according to the access modes in the grfMode parameter, subject to the following restrictions:
+ ///
+ ///
+ /// Sharing mode behavior and transactional isolation depend on the ILockBytes implementation supporting LockRegion and UnlockRegion
+ /// with LOCK_ONLYONCE semantics. Implementations can indicate to structured storage they support this functionality by setting the
+ /// LOCK_ONLYONCE bit in the grfLocksSupported member of STATSTG. If an ILockBytes implementation does not
+ /// support this functionality, sharing modes will not be enforced, and root-level transactional commits will not coordinate properly
+ /// with other transactional instances opened on the same byte array. Applications that use an ILockBytes implementation that
+ /// does not support region locking, such as the CreateStreamOnHGlobal implementation, should avoid opening multiple concurrent
+ /// instances on the same byte array.
+ ///
+ /// StgCreateDocfileOnILockBytes does not support simple mode. The STGM_SIMPLE flag, if present, is ignored.
+ ///
+ /// For conversion purposes, the file is considered to already exist. As a result, it is not useful to use the STGM_FAILIFTHERE
+ /// value, because it causes an error to be returned. However, both STGM_CREATE and STGM_CONVERT remain useful.
+ ///
+ ///
+ /// The ability to build a compound file on top of a byte-array object is provided to support having the data (underneath an IStorage
+ /// and IStream tree structure) live in a nonpersistent space. Given this capability, there is nothing preventing a document that is
+ /// stored in a file from using this facility. For example, a container might do this to minimize the impact on its file format
+ /// caused by adopting COM. However, it is recommended that COM documents adopt the IStorage interface for their own
+ /// outer-level storage. This has the following advantages:
+ ///
+ ///
+ /// -
+ ///
+ /// The storage structure of the document is the same as its storage structure when it is an embedded object, reducing the number of
+ /// cases the application needs to handle.
+ ///
+ ///
+ /// -
+ ///
+ /// One can write tools to access the OLE embedded and linked objects within the document without special knowledge of the document's
+ /// file format. An example of such a tool is a copy utility that copies all the documents included in a container containing linked
+ /// objects. A copy utility like this needs access to the contained links to determine the extent of files to be copied.
+ ///
+ ///
+ /// -
+ ///
+ /// The IStorage implementation addresses the problem of how to commit the changes to the file. An application using the ILockBytes
+ /// interface must handle these issues itself.
+ ///
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgcreatedocfileonilockbytes HRESULT
+ // StgCreateDocfileOnILockBytes( ILockBytes *plkbyt, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "8af5098d-db04-4273-8f5f-6d1a1d9541de")]
+ public static extern HRESULT StgCreateDocfileOnILockBytes([In] ILockBytes plkbyt, STGM grfMode, [Optional] uint reserved, out IStorage ppstgOpen);
+
+ ///
+ /// The StgCreatePropSetStg function creates a property set storage object from a specified storage object. The property set
+ /// storage object supplies the system-provided, stand-alone implementation of the IPropertySetStorage interface.
+ ///
+ /// A pointer to the storage object that contains or will contain one or more property sets.
+ /// Reserved for future use; must be zero.
+ ///
+ /// A pointer to IPropertySetStorage* pointer variable that receives the interface pointer to the property-set storage object.
+ ///
+ /// This function supports the standard return value E_INVALIDARG as well as the following:
+ ///
+ ///
+ /// The StgCreatePropSetStg function creates an IPropertySetStorage interface that will act on the given IStorage interface
+ /// specified by the pStorage parameter. This function does not modify this IStorage by itself, although subsequent calls to
+ /// the IPropertySetStorage interface might.
+ ///
+ ///
+ /// StgCreatePropSetStg calls IUnknown::AddRef on the storage object specified by pStorage. The caller must release the object
+ /// when it is no longer required by calling Release.
+ ///
+ /// Examples
+ /// The following example code shows how this function creates a property set within a storage object.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgcreatepropsetstg HRESULT StgCreatePropSetStg(
+ // IStorage *pStorage, DWORD dwReserved, IPropertySetStorage **ppPropSetStg );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "0113b29d-23aa-4590-b8ac-33789a7a2ed4")]
+ public static extern HRESULT StgCreatePropSetStg([In] IStorage pStorage, [Optional] uint dwReserved, out IPropertySetStorage ppPropSetStg);
+
+ ///
+ /// The StgCreatePropStg function creates and opens a property set in a specified storage or stream object. The property set
+ /// supplies the system-provided, stand-alone implementation of the IPropertyStorage interface.
+ ///
+ ///
+ /// A pointer to the IUnknown interface on the storage or stream object that stores the new property set.
+ ///
+ /// The FMTID of the property set to be created.
+ ///
+ /// A Pointer to the initial CLSID for this property set. May be NULL, in which case pclsid is set to all zeroes.
+ ///
+ /// The values from PROPSETFLAG Constants that determine how the property set is created and opened.
+ /// Reserved; must be zero.
+ ///
+ /// The address of an IPropertyStorage* pointer variable that receives the interface pointer to the new property set.
+ ///
+ /// This function supports the standard return values E_INVALIDARG and E_UNEXPECTED, in addition to the following:
+ ///
+ ///
+ /// StgCreatePropStg creates and opens a new property set which supplies the system-provided, stand-alone implementation of
+ /// the IPropertyStorage interface. The new property set is contained in the storage or stream object specified by pUnk. The value of
+ /// the grfFlags parameter indicates whether pUnk specifies a storage or stream object. For example, if PROPSETFLAG_NONSIMPLE is set,
+ /// then pUnk can be queried for an IStorage interface on a storage object.
+ ///
+ ///
+ /// In either case, this function calls pUnk->AddRef for the storage or stream object containing the property set. It is the
+ /// responsibility of the caller to release the object when it is no longer needed.
+ ///
+ ///
+ /// This function is similar to the IPropertySetStorage::Create method. However, StgCreatePropStg adds the pUnk parameter and
+ /// supports the PROPSETFLAG_UNBUFFERED value for the grfFlags parameter. Use this function instead of the Create method if
+ /// you have an IStorage interface that does not support the IPropertySetStorage interface, or if you want to use the
+ /// PROPSETFLAG_UNBUFFERED value. For more information about using this PROPSETFLAG_UNBUFFERED enumeration value, see PROPSETFLAG Constants.
+ ///
+ ///
+ /// The property set automatically contains code page and locale identifier (ID) properties. These are set to the current system
+ /// default and the current user default, respectively.
+ ///
+ ///
+ /// The grfFlags parameter is a combination of values taken from PROPSETFLAG Constants. The new enumeration value
+ /// PROPSETFLAG_UNBUFFERED is supported. For more information, see PROPSETFLAG Constants.
+ ///
+ ///
+ /// This function is exported out of the redistributable Iprop.dll, which is included in Windows NT 4.0 with Service Pack 2 (SP2) and
+ /// later and available as a redistributable in Windows 95, Windows 98 and later. In Windows 2000 and Windows XP, it is exported out
+ /// of ole32.dll. It can also be exported out of iprop.dll in Windows 2000 and Windows XP, but the call gets forwarded to ole32.dll.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgcreatepropstg HRESULT StgCreatePropStg( IUnknown
+ // *pUnk, REFFMTID fmtid, const CLSID *pclsid, DWORD grfFlags, DWORD dwReserved, IPropertyStorage **ppPropStg );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "fc171888-3723-4894-a356-1b234352c4e8")]
+ public static extern HRESULT StgCreatePropStg([In, MarshalAs(UnmanagedType.IUnknown)] object pUnk, in Guid fmtid, in Guid pclsid, PROPSETFLAG grfFlags, [Optional] uint dwReserved, out IPropertyStorage ppPropStg);
+
+ ///
+ ///
+ /// The StgCreateStorageEx function creates a new storage object using a provided implementation for the IStorage or
+ /// IPropertySetStorage interfaces. To open an existing file, use the StgOpenStorageEx function instead.
+ ///
+ ///
+ /// Applications written for Windows 2000, Windows Server 2003 and Windows XP must use StgCreateStorageEx rather than
+ /// StgCreateDocfile to take advantage of the enhanced Windows 2000 and Windows XP Structured Storage features.
+ ///
+ ///
+ ///
+ ///
+ /// A pointer to the path of the file to create. It is passed uninterpreted to the file system. This can be a relative name or
+ /// NULL. If NULL, a temporary file is allocated with a unique name. If non- NULL, the string size must not
+ /// exceed MAX_PATH characters.
+ ///
+ /// Windows 2000: Unlike the CreateFile function, you cannot exceed the MAX_PATH limit by using the "\?" prefix.
+ ///
+ ///
+ /// A value that specifies the access mode to use when opening the new storage object. For more information, see STGM Constants. If
+ /// the caller specifies transacted mode together with STGM_CREATE or STGM_CONVERT, the overwrite or conversion takes place when the
+ /// commit operation is called for the root storage. If IStorage::Commit is not called for the root storage object, previous contents
+ /// of the file will be restored. STGM_CREATE and STGM_CONVERT cannot be combined with the STGM_NOSNAPSHOT flag, because a snapshot
+ /// copy is required when a file is overwritten or converted in the transacted mode.
+ ///
+ /// A value that specifies the storage file format. For more information, see the STGFMT enumeration.
+ ///
+ /// A value that depends on the value of the stgfmt parameter.
+ ///
+ ///
+ /// Parameter Values
+ /// Meaning
+ ///
+ /// -
+ /// STGFMT_DOCFILE
+ ///
+ /// 0, or FILE_FLAG_NO_BUFFERING. For more information, see CreateFile. If the sector size of the file, specified in pStgOptions, is
+ /// not an integer multiple of the underlying disk's physical sector size, this operation will fail.
+ ///
+ ///
+ /// -
+ /// All other values of stgfmt
+ /// Must be 0.
+ ///
+ ///
+ ///
+ ///
+ /// The pStgOptions parameter is valid only if the stgfmt parameter is set to STGFMT_DOCFILE. If the stgfmt parameter is set to
+ /// STGFMT_DOCFILE, pStgOptions points to the STGOPTIONS structure, which specifies features of the storage object, such as the
+ /// sector size. This parameter may be NULL, which creates a storage object with a default sector size of 512 bytes. If non-
+ /// NULL, the ulSectorSize member must be set to either 512 or 4096. If set to 4096, STGM_SIMPLE may not be specified
+ /// in the grfMode parameter. The usVersion member must be set before calling StgCreateStorageEx. For more information,
+ /// see STGOPTIONS.
+ ///
+ ///
+ ///
+ /// Enables the ACLs to be set when the file is created. If not NULL, needs to be a pointer to the SECURITY_ATTRIBUTES
+ /// structure. See CreateFile for information on how to set ACLs on files.
+ ///
+ /// Windows Server 2003, Windows 2000 Server, Windows XP and Windows 2000 Professional: Value must be NULL.
+ ///
+ ///
+ /// A value that specifies the interface identifier (IID) of the interface pointer to return. This IID may be for the IStorage
+ /// interface or the IPropertySetStorage interface.
+ ///
+ ///
+ /// A pointer to an interface pointer variable that receives a pointer for an interface on the new storage object; contains
+ /// NULL if operation failed.
+ ///
+ ///
+ /// This function can also return any file system errors or system errors wrapped in an HRESULT. For more information, see
+ /// Error Handling Strategies and Handling Unknown Errors.
+ ///
+ ///
+ ///
+ /// When an application modifies its file, it usually creates a copy of the original. The StgCreateStorageEx function is one
+ /// way for creating a copy. This function works indirectly with the Encrypting File System (EFS) duplication API. When you use this
+ /// function, you will need to set the options for the file storage in the STGOPTIONS structure.
+ ///
+ ///
+ /// StgCreateStorageEx is a superset of the StgCreateDocfile function, and should be used by new code. Future enhancements to
+ /// Structured Storage will be exposed through the StgCreateStorageEx function. See the following Requirements section for
+ /// information on supported platforms.
+ ///
+ ///
+ /// The StgCreateStorageEx function creates a new storage object using one of the system-provided, structured-storage
+ /// implementations. This function can be used to obtain an IStorage compound file implementation, an IPropertySetStorage compound
+ /// file implementation, or to obtain an IPropertySetStorage NTFS implementation.
+ ///
+ ///
+ /// When a new file is created, the storage implementation used depends on the flag that you specify and on the type of drive on
+ /// which the file is stored. For more information, see the STGFMT enumeration.
+ ///
+ ///
+ /// StgCreateStorageEx creates the file if it does not exist. If it does exist, the use of the STGM_CREATE, STGM_CONVERT, and
+ /// STGM_FAILIFTHERE flags in the grfMode parameter indicate how to proceed. For more information on these values, see STGM
+ /// Constants. It is not valid, in direct mode, to specify the STGM_READ mode in the grfMode parameter (direct mode is indicated by
+ /// not specifying the STGM_TRANSACTED flag). This function cannot be used to open an existing file; use the StgOpenStorageEx
+ /// function instead.
+ ///
+ ///
+ /// You can use the StgCreateStorageEx function to get access to the root storage of a structured-storage document or the
+ /// property set storage of any file that supports property sets. See the STGFMT documentation for information about which IIDs are
+ /// supported for different STGFMT values.
+ ///
+ ///
+ /// When a file is created with this function to access the NTFS property set implementation, special sharing rules apply. For more
+ /// information, see IPropertySetStorage-NTFS Implementation.
+ ///
+ ///
+ /// If a compound file is created in transacted mode (by specifying STGM_TRANSACTED) and read-only mode (by specifying STGM_READ), it
+ /// is possible to make changes to the returned storage object. For example, it is possible to call IStorage::CreateStream. However,
+ /// it is not possible to commit those changes by calling IStorage::Commit. Therefore, such changes will be lost.
+ ///
+ ///
+ /// Specifying STGM_SIMPLE provides a much faster implementation of a compound file object in a limited, but frequently used case
+ /// involving applications that require a compound file implementation with multiple streams and no storages. For more information,
+ /// see STGM Constants. It is not valid to specify that STGM_TRANSACTED if STGM_SIMPLE is specified.
+ ///
+ ///
+ /// The simple mode does not support all the methods on IStorage. Specifically, in simple mode, supported IStorage methods are
+ /// CreateStream, Commit, and SetClass as well as the COM IUnknown methods of QueryInterface, AddRef and Release. In addition,
+ /// SetElementTimes is supported with a NULL name, allowing applications to set times on a root storage. All the other methods
+ /// of IStorage return STG_E_INVALIDFUNCTION.
+ ///
+ ///
+ /// If the grfMode parameter specifies STGM_TRANSACTED and no file yet exists with the name specified by the pwcsName parameter, the
+ /// file is created immediately. In an access-controlled file system, the caller must have write permissions for the file system
+ /// directory in which the compound file is created. If STGM_TRANSACTED is not specified, and STGM_CREATE is specified, an existing
+ /// file with the same name is destroyed before creating the new file.
+ ///
+ ///
+ /// You can also use StgCreateStorageEx to create a temporary compound file by passing a NULL value for the pwcsName
+ /// parameter. However, these files are temporary only in the sense that they have a unique system-provided name – one that is
+ /// probably meaningless to the user. The caller is responsible for deleting the temporary file when finished with it, unless
+ /// STGM_DELETEONRELEASE was specified for the grfMode parameter. For more information on these flags, see STGM Constants.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgcreatestorageex HRESULT StgCreateStorageEx( const
+ // WCHAR *pwcsName, DWORD grfMode, DWORD stgfmt, DWORD grfAttrs, STGOPTIONS *pStgOptions, PSECURITY_DESCRIPTOR pSecurityDescriptor,
+ // REFIID riid, void **ppObjectOpen );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "6442977d-e980-419e-abe9-9d15dbb045c1")]
+ public static extern HRESULT StgCreateStorageEx([In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pwcsName, STGM grfMode, STGFMT stgfmt, FileFlagsAndAttributes grfAttrs, in STGOPTIONS pStgOptions,
+ [Optional] PSECURITY_DESCRIPTOR pSecurityDescriptor, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 6)] out object ppObjectOpen);
+
+ ///
+ ///
+ /// The StgCreateStorageEx function creates a new storage object using a provided implementation for the IStorage or
+ /// IPropertySetStorage interfaces. To open an existing file, use the StgOpenStorageEx function instead.
+ ///
+ ///
+ /// Applications written for Windows 2000, Windows Server 2003 and Windows XP must use StgCreateStorageEx rather than
+ /// StgCreateDocfile to take advantage of the enhanced Windows 2000 and Windows XP Structured Storage features.
+ ///
+ ///
+ ///
+ ///
+ /// A pointer to the path of the file to create. It is passed uninterpreted to the file system. This can be a relative name or
+ /// NULL. If NULL, a temporary file is allocated with a unique name. If non- NULL, the string size must not
+ /// exceed MAX_PATH characters.
+ ///
+ /// Windows 2000: Unlike the CreateFile function, you cannot exceed the MAX_PATH limit by using the "\?" prefix.
+ ///
+ ///
+ /// A value that specifies the access mode to use when opening the new storage object. For more information, see STGM Constants. If
+ /// the caller specifies transacted mode together with STGM_CREATE or STGM_CONVERT, the overwrite or conversion takes place when the
+ /// commit operation is called for the root storage. If IStorage::Commit is not called for the root storage object, previous contents
+ /// of the file will be restored. STGM_CREATE and STGM_CONVERT cannot be combined with the STGM_NOSNAPSHOT flag, because a snapshot
+ /// copy is required when a file is overwritten or converted in the transacted mode.
+ ///
+ /// A value that specifies the storage file format. For more information, see the STGFMT enumeration.
+ ///
+ /// A value that depends on the value of the stgfmt parameter.
+ ///
+ ///
+ /// Parameter Values
+ /// Meaning
+ ///
+ /// -
+ /// STGFMT_DOCFILE
+ ///
+ /// 0, or FILE_FLAG_NO_BUFFERING. For more information, see CreateFile. If the sector size of the file, specified in pStgOptions, is
+ /// not an integer multiple of the underlying disk's physical sector size, this operation will fail.
+ ///
+ ///
+ /// -
+ /// All other values of stgfmt
+ /// Must be 0.
+ ///
+ ///
+ ///
+ ///
+ /// The pStgOptions parameter is valid only if the stgfmt parameter is set to STGFMT_DOCFILE. If the stgfmt parameter is set to
+ /// STGFMT_DOCFILE, pStgOptions points to the STGOPTIONS structure, which specifies features of the storage object, such as the
+ /// sector size. This parameter may be NULL, which creates a storage object with a default sector size of 512 bytes. If non-
+ /// NULL, the ulSectorSize member must be set to either 512 or 4096. If set to 4096, STGM_SIMPLE may not be specified
+ /// in the grfMode parameter. The usVersion member must be set before calling StgCreateStorageEx. For more information,
+ /// see STGOPTIONS.
+ ///
+ ///
+ ///
+ /// Enables the ACLs to be set when the file is created. If not NULL, needs to be a pointer to the SECURITY_ATTRIBUTES
+ /// structure. See CreateFile for information on how to set ACLs on files.
+ ///
+ /// Windows Server 2003, Windows 2000 Server, Windows XP and Windows 2000 Professional: Value must be NULL.
+ ///
+ ///
+ /// A value that specifies the interface identifier (IID) of the interface pointer to return. This IID may be for the IStorage
+ /// interface or the IPropertySetStorage interface.
+ ///
+ ///
+ /// A pointer to an interface pointer variable that receives a pointer for an interface on the new storage object; contains
+ /// NULL if operation failed.
+ ///
+ ///
+ /// This function can also return any file system errors or system errors wrapped in an HRESULT. For more information, see
+ /// Error Handling Strategies and Handling Unknown Errors.
+ ///
+ ///
+ ///
+ /// When an application modifies its file, it usually creates a copy of the original. The StgCreateStorageEx function is one
+ /// way for creating a copy. This function works indirectly with the Encrypting File System (EFS) duplication API. When you use this
+ /// function, you will need to set the options for the file storage in the STGOPTIONS structure.
+ ///
+ ///
+ /// StgCreateStorageEx is a superset of the StgCreateDocfile function, and should be used by new code. Future enhancements to
+ /// Structured Storage will be exposed through the StgCreateStorageEx function. See the following Requirements section for
+ /// information on supported platforms.
+ ///
+ ///
+ /// The StgCreateStorageEx function creates a new storage object using one of the system-provided, structured-storage
+ /// implementations. This function can be used to obtain an IStorage compound file implementation, an IPropertySetStorage compound
+ /// file implementation, or to obtain an IPropertySetStorage NTFS implementation.
+ ///
+ ///
+ /// When a new file is created, the storage implementation used depends on the flag that you specify and on the type of drive on
+ /// which the file is stored. For more information, see the STGFMT enumeration.
+ ///
+ ///
+ /// StgCreateStorageEx creates the file if it does not exist. If it does exist, the use of the STGM_CREATE, STGM_CONVERT, and
+ /// STGM_FAILIFTHERE flags in the grfMode parameter indicate how to proceed. For more information on these values, see STGM
+ /// Constants. It is not valid, in direct mode, to specify the STGM_READ mode in the grfMode parameter (direct mode is indicated by
+ /// not specifying the STGM_TRANSACTED flag). This function cannot be used to open an existing file; use the StgOpenStorageEx
+ /// function instead.
+ ///
+ ///
+ /// You can use the StgCreateStorageEx function to get access to the root storage of a structured-storage document or the
+ /// property set storage of any file that supports property sets. See the STGFMT documentation for information about which IIDs are
+ /// supported for different STGFMT values.
+ ///
+ ///
+ /// When a file is created with this function to access the NTFS property set implementation, special sharing rules apply. For more
+ /// information, see IPropertySetStorage-NTFS Implementation.
+ ///
+ ///
+ /// If a compound file is created in transacted mode (by specifying STGM_TRANSACTED) and read-only mode (by specifying STGM_READ), it
+ /// is possible to make changes to the returned storage object. For example, it is possible to call IStorage::CreateStream. However,
+ /// it is not possible to commit those changes by calling IStorage::Commit. Therefore, such changes will be lost.
+ ///
+ ///
+ /// Specifying STGM_SIMPLE provides a much faster implementation of a compound file object in a limited, but frequently used case
+ /// involving applications that require a compound file implementation with multiple streams and no storages. For more information,
+ /// see STGM Constants. It is not valid to specify that STGM_TRANSACTED if STGM_SIMPLE is specified.
+ ///
+ ///
+ /// The simple mode does not support all the methods on IStorage. Specifically, in simple mode, supported IStorage methods are
+ /// CreateStream, Commit, and SetClass as well as the COM IUnknown methods of QueryInterface, AddRef and Release. In addition,
+ /// SetElementTimes is supported with a NULL name, allowing applications to set times on a root storage. All the other methods
+ /// of IStorage return STG_E_INVALIDFUNCTION.
+ ///
+ ///
+ /// If the grfMode parameter specifies STGM_TRANSACTED and no file yet exists with the name specified by the pwcsName parameter, the
+ /// file is created immediately. In an access-controlled file system, the caller must have write permissions for the file system
+ /// directory in which the compound file is created. If STGM_TRANSACTED is not specified, and STGM_CREATE is specified, an existing
+ /// file with the same name is destroyed before creating the new file.
+ ///
+ ///
+ /// You can also use StgCreateStorageEx to create a temporary compound file by passing a NULL value for the pwcsName
+ /// parameter. However, these files are temporary only in the sense that they have a unique system-provided name – one that is
+ /// probably meaningless to the user. The caller is responsible for deleting the temporary file when finished with it, unless
+ /// STGM_DELETEONRELEASE was specified for the grfMode parameter. For more information on these flags, see STGM Constants.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgcreatestorageex HRESULT StgCreateStorageEx( const
+ // WCHAR *pwcsName, DWORD grfMode, DWORD stgfmt, DWORD grfAttrs, STGOPTIONS *pStgOptions, PSECURITY_DESCRIPTOR pSecurityDescriptor,
+ // REFIID riid, void **ppObjectOpen );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "6442977d-e980-419e-abe9-9d15dbb045c1")]
+ public static extern HRESULT StgCreateStorageEx([In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pwcsName, STGM grfMode, STGFMT stgfmt, FileFlagsAndAttributes grfAttrs, [Optional] IntPtr pStgOptions,
+ [Optional] PSECURITY_DESCRIPTOR pSecurityDescriptor, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 6)] out object ppObjectOpen);
+
+ /// The StgIsStorageFile function indicates whether a particular disk file contains a storage object.
+ ///
+ /// Pointer to the null-terminated Unicode string name of the disk file to be examined. The pwcsName parameter is passed
+ /// uninterpreted to the underlying file system.
+ ///
+ ///
+ /// StgIsStorageFile function can also return any file system errors or system errors wrapped in an HRESULT. See Error
+ /// Handling Strategies and Handling Unknown Errors
+ ///
+ ///
+ ///
+ /// At the beginning of the disk file underlying a storage object is a signature distinguishing a storage object from other file
+ /// formats. The StgIsStorageFile function is useful to applications whose documents use a disk file format that might or
+ /// might not use storage objects.
+ ///
+ /// If a root compound file has been created in transacted mode but not yet committed, this method still return S_OK.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgisstoragefile HRESULT StgIsStorageFile( const WCHAR
+ // *pwcsName );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "6a0d2da5-4d5c-4da7-9ea6-3b52cd6673fc")]
+ public static extern HRESULT StgIsStorageFile([MarshalAs(UnmanagedType.LPWStr)] string pwcsName);
+
+ /// The StgIsStorageILockBytes function indicates whether the specified byte array contains a storage object.
+ /// ILockBytes pointer to the byte array to be examined.
+ ///
+ /// This function can also return any file system errors, or system errors wrapped in an HRESULT, or ILockBytes interface
+ /// error return values. See Error Handling Strategies and Handling Unknown Errors
+ ///
+ ///
+ /// At the beginning of the byte array underlying a storage object is a signature distinguishing a storage object (supporting the
+ /// IStorage interface) from other file formats. The StgIsStorageILockBytes function is useful to applications whose documents
+ /// use a byte array (a byte array object supports the ILockBytes interface) that might or might not use storage objects.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgisstorageilockbytes HRESULT StgIsStorageILockBytes(
+ // ILockBytes *plkbyt );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "ce0e29fd-1b21-4064-8e37-1a5d5df8bb61")]
+ public static extern HRESULT StgIsStorageILockBytes([In] ILockBytes plkbyt);
+
+ ///
+ /// The StgOpenPropStg function opens a specified property set in a specified storage or stream object. The property set
+ /// supplies the system-provided, stand-alone implementation of the IPropertyStorage interface.
+ ///
+ ///
+ /// The interface pointer for IUnknown interface on the storage or stream object that contains the requested property set object.
+ ///
+ /// The FMTID of the property set to be opened.
+ /// The values from PROPSETFLAG Constants.
+ /// Reserved for future use; must be zero.
+ ///
+ /// A pointer to an IPropertyStorage* pointer variable that receives the interface pointer to the requested property set.
+ ///
+ /// This function supports the standard return values E_INVALIDARG and E_UNEXPECTED, in addition to the following:
+ ///
+ ///
+ /// StgOpenPropStg opens the requested property set and supplies the system-provided, stand-alone implementation of the
+ /// IPropertyStorage interface. The requested property set is contained in the storage or stream object specified by pUnk. The value
+ /// of the grfFlags parameter indicates whether pUnk specifies a storage or stream object. For example, if PROPSETFLAG_NONSIMPLE is
+ /// set, then pUnk can be queried for an IStorage interface on a storage object.
+ ///
+ ///
+ /// In either case, this function calls pUnk->AddRef for the storage or stream object containing the property set. The caller must
+ /// release the object when no longer required.
+ ///
+ ///
+ /// This function is similar to the IPropertySetStorage::Open method. However, StgOpenPropStg adds the pUnk and grfFlags
+ /// parameters, including the PROPSETFLAG_UNBUFFERED value for the grfFlags parameter. Use this function instead of the Open method
+ /// if you have an IStorage interface that does not support the IPropertySetStorage interface, or if you want to use the
+ /// PROPSETFLAG_UNBUFFERED value. For more information about using PROPSETFLAG_UNBUFFERED, see PROPSETFLAG Constants.
+ ///
+ ///
+ /// The grfFlags parameter is a combination of values taken from PROPSETFLAG Constants. The new enumeration value
+ /// PROPSETFLAG_UNBUFFERED is supported. For more information, see PROPSETFLAG Constants.
+ ///
+ ///
+ /// This function is exported out of the redistributable iprop.dll, which is included in Windows NT 4.0 with Service Pack 2 (SP2) and
+ /// available as a redistributable in Windows 95 and later. In Windows 2000, it is exported out of Ole32.dll. It can also be exported
+ /// out of iprop.dll in Windows 2000, but the call gets forwarded to ole32.dll.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgopenpropstg HRESULT StgOpenPropStg( IUnknown *pUnk,
+ // REFFMTID fmtid, DWORD grfFlags, DWORD dwReserved, IPropertyStorage **ppPropStg );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "ecc78e49-f1c2-4c2d-8390-b2b6f1dc776e")]
+ public static extern HRESULT StgOpenPropStg([MarshalAs(UnmanagedType.IUnknown)] object pUnk, in Guid fmtid, PROPSETFLAG grfFlags, [Optional] uint dwReserved, out IPropertyStorage ppPropStg);
+
+ ///
+ ///
+ /// The StgOpenStorage function opens an existing root storage object in the file system. Use this function to open compound
+ /// files. Do not use it to open directories, files, or summary catalogs. Nested storage objects can only be opened using their
+ /// parent IStorage::OpenStorage method.
+ ///
+ ///
+ /// Note Applications should use the new function, StgOpenStorageEx, instead of StgOpenStorage, to take advantage of
+ /// the enhanced and Windows Structured Storage features. This function, StgOpenStorage, still exists for compatibility with
+ /// applications running on Windows 2000.
+ ///
+ ///
+ ///
+ /// A pointer to the path of the null-terminated Unicode string file that contains the storage object to open. This parameter
+ /// is ignored if the pstgPriority parameter is not NULL.
+ ///
+ ///
+ ///
+ /// A pointer to the IStorage interface that should be NULL. If not NULL, this parameter is used as described below in
+ /// the Remarks section.
+ ///
+ ///
+ /// After StgOpenStorage returns, the storage object specified in pStgPriority may have been released and should no longer be used.
+ ///
+ ///
+ /// Specifies the access mode to use to open the storage object.
+ ///
+ /// If not NULL, pointer to a block of elements in the storage to be excluded as the storage object is opened. The exclusion
+ /// occurs regardless of whether a snapshot copy happens on the open. Can be NULL.
+ ///
+ /// Indicates reserved for future use; must be zero.
+ /// A pointer to a IStorage* pointer variable that receives the interface pointer to the opened storage.
+ ///
+ /// The StgOpenStorage function can also return any file system errors or system errors wrapped in an HRESULT. For more
+ /// information, see Error Handling Strategies and Handling Unknown Errors.
+ ///
+ ///
+ ///
+ /// The StgOpenStorage function opens the specified root storage object according to the access mode in the grfMode parameter,
+ /// and, if successful, supplies an IStorage pointer to the opened storage object in the ppstgOpen parameter.
+ ///
+ ///
+ /// To support the simple mode for saving a storage object with no substorages, the StgOpenStorage function accepts one of the
+ /// following two flag combinations as valid modes in the grfMode parameter.
+ ///
+ ///
+ /// To support the single-writer, multireader, direct mode, the first flag combination is the valid grfMode parameter for the writer.
+ /// The second flag combination is valid for readers.
+ ///
+ /// In direct mode, one of the following three combinations are valid.
+ ///
+ /// Note Opening a storage object in read/write mode without denying write permission to others (the grfMode parameter
+ /// specifies STGM_SHARE_DENY_WRITE) can be a time-consuming operation because the StgOpenStorage call must make a snapshot of
+ /// the entire storage object.
+ ///
+ ///
+ /// Applications often try to open storage objects with the following access permissions. If the application succeeds, it never needs
+ /// to make a snapshot copy.
+ ///
+ ///
+ /// The application can revert to using the permissions and make a snapshot copy, if the previous access permissions fail. The
+ /// application should prompt the user before making a time-consuming copy.
+ ///
+ ///
+ /// If the document-sharing semantics implied by the access modes are appropriate, the application could try to open the storage as
+ /// follows. In this case, if the application succeeds, a snapshot copy will not have been made (because STGM_SHARE_DENY_WRITE
+ /// was specified, denying others write access).
+ ///
+ ///
+ /// Note To reduce the expense of making a snapshot copy, applications can open storage objects in priority mode (grfMode
+ /// specifies STGM_PRIORITY).
+ ///
+ ///
+ /// The snbExclude parameter specifies a set of element names in this storage object that are to be emptied as the storage object is
+ /// opened: streams are set to a length of zero; storage objects have all their elements removed. By excluding certain streams, the
+ /// expense of making a snapshot copy can be significantly reduced. Almost always, this approach is used after first opening the
+ /// storage object in priority mode, then completely reading the now-excluded elements into memory. This earlier priority-mode
+ /// opening of the storage object should be passed through the pstgPriority parameter to remove the exclusion implied by priority
+ /// mode. The calling application is responsible for rewriting the contents of excluded items before committing. Thus, this technique
+ /// is most likely useful only to applications whose documents do not require constant access to their storage objects while they are active.
+ ///
+ ///
+ /// The pstgPriority parameter is intended as a convenience for callers replacing an existing storage object, often one opened in
+ /// priority mode, with a new storage object opened on the same file but in a different mode. When pstgPriority is not NULL,
+ /// it is used to specify the file name instead of pwcsName, which is ignored. However, it is recommended that applications always
+ /// pass NULL for pstgPriority because StgOpenStorage releases the object under some circumstances, and does not
+ /// release it under other circumstances. In particular, if the function returns a failure result, it is not possible for the caller
+ /// to determine whether or not the storage object was released.
+ ///
+ ///
+ /// The functionality of the pstgPriority parameter can be duplicated by the caller in a safer manner as shown in the following example:
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgopenstorage HRESULT StgOpenStorage( const WCHAR
+ // *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstgOpen );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "5ff18dc8-b24f-42bb-8c32-efc4d3696687")]
+ public static extern HRESULT StgOpenStorage([In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pwcsName, [In, Optional] IStorage pstgPriority, STGM grfMode, SNB snbExclude, [Optional] uint reserved, out IStorage ppstgOpen);
+
+ ///
+ ///
+ /// The StgOpenStorageEx function opens an existing root storage object in the file system. Use this function to open Compound
+ /// Files and regular files. To create a new file, use the StgCreateStorageEx function.
+ ///
+ ///
+ /// Note To use enhancements, all Windows 2000, Windows XP, and Windows Server 2003 applications should call
+ /// StgOpenStorageEx, instead of StgOpenStorage. The StgOpenStorage function is used for compatibility with Windows
+ /// 2000 and earlier applications.
+ ///
+ ///
+ ///
+ ///
+ /// A pointer to the path of the null-terminated Unicode string file that contains the storage object. This string size cannot exceed
+ /// MAX_PATH characters.
+ ///
+ ///
+ /// Windows Server 2003 and Windows XP/2000: Unlike the CreateFile function, the MAX_PATH limit cannot be exceeded by
+ /// using the "\?" prefix.
+ ///
+ ///
+ ///
+ ///
+ /// A value that specifies the access mode to open the new storage object. For more information, see STGM Constants. If the caller
+ /// specifies transacted mode together with STGM_CREATE or STGM_CONVERT, the overwrite or conversion occurs when the
+ /// commit operation is called for the root storage. If IStorage::Commit is not called for the root storage object, previous contents
+ /// of the file will be restored. STGM_CREATE and STGM_CONVERT cannot be combined with the STGM_NOSNAPSHOT flag,
+ /// because a snapshot copy is required when a file is overwritten or converted in transacted mode.
+ ///
+ ///
+ /// If the storage object is opened in direct mode ( STGM_DIRECT) with access to either STGM_WRITE or
+ /// STGM_READWRITE, the sharing mode must be STGM_SHARE_EXCLUSIVE unless the STGM_DIRECT_SWMR mode is specified.
+ /// For more information, see the Remarks section. If the storage object is opened in direct mode with access to STGM_READ,
+ /// the sharing mode must be either STGM_SHARE_EXCLUSIVE or STGM_SHARE_DENY_WRITE, unless STGM_PRIORITY or
+ /// STGM_DIRECT_SWMR is specified. For more information, see the Remarks section.
+ ///
+ ///
+ /// The mode in which a file is opened can affect implementation performance. For more information, see Compound File Implementation Limits.
+ ///
+ ///
+ /// A value that specifies the storage file format. For more information, see the STGFMT enumeration.
+ ///
+ /// A value that depends upon the value of the stgfmt parameter.
+ ///
+ /// STGFMT_DOCFILE must be zero (0) or FILE_FLAG_NO_BUFFERING. For more information about this value, see CreateFile.
+ /// If the sector size of the file, specified in pStgOptions, is not an integer multiple of the physical sector size of the
+ /// underlying disk, then this operation will fail. All other values of stgfmt must be zero.
+ ///
+ ///
+ ///
+ /// A pointer to an STGOPTIONS structure that contains data about the storage object opened. The pStgOptions parameter is valid only
+ /// if the stgfmt parameter is set to STGFMT_DOCFILE. The usVersion member must be set before calling
+ /// StgOpenStorageEx. For more information, see the STGOPTIONS structure.
+ ///
+ /// Reserved; must be zero.
+ ///
+ /// A value that specifies the GUID of the interface pointer to return. Can also be the header-specified value for
+ /// IID_IStorage to obtain the IStorage interface or for IID_IPropertySetStorage to obtain the IPropertySetStorage interface.
+ ///
+ ///
+ /// The address of an interface pointer variable that receives a pointer for an interface on the storage object opened; contains
+ /// NULL if operation failed.
+ ///
+ ///
+ /// This function can also return any file system errors or system errors wrapped in an HRESULT. For more information, see
+ /// Error Handling Strategies and Handling Unknown Errors.
+ ///
+ ///
+ ///
+ /// StgOpenStorageEx is a superset of the StgOpenStorage function, and should be used by new code. Future enhancements to
+ /// structured storage will be exposed through this function. For more information about supported platforms, see the Requirements section.
+ ///
+ ///
+ /// The StgOpenStorageEx function opens the specified root storage object according to the access mode in the grfMode
+ /// parameter, and, if successful, supplies an interface pointer for the opened storage object in the ppObjectOpen parameter. This
+ /// function can be used to obtain an IStorage compound file implementation, an IPropertySetStorage compound file implementation, or
+ /// an NTFS file system implementation of IPropertySetStorage.
+ ///
+ ///
+ /// When you open a file, the system selects a structured storage implementation depending on which STGFMT flag you specify on the
+ /// file type and on the type of drive where the file is stored.
+ ///
+ ///
+ /// Use the StgOpenStorageEx function to access the root storage of a structured storage document or the property set storage
+ /// of any file that supports property sets. For more information about which interface identifiers (IIDs) are supported for the
+ /// different STGFMT values, see STGFMT.
+ ///
+ ///
+ /// When a file is opened with this function to access the NTFS property set implementation, special sharing rules apply. For more
+ /// information, see IPropertySetStorage-NTFS Implementation.
+ ///
+ ///
+ /// If a compound file is opened in transacted mode, by specifying STGM_TRANSACTED, and read-only mode, by specifying STGM_READ, it
+ /// is possible to change the returned storage object. For example, it is possible to call IStorage::CreateStream. However, it is not
+ /// possible to commit those changes by calling IStorage::Commit. Therefore, such changes will be lost.
+ ///
+ ///
+ /// It is not valid to use the STGM_CREATE, STGM_DELETEONRELEASE, or STGM_CONVERT flags in the grfMode parameter
+ /// for this function.
+ ///
+ ///
+ /// To support the simple mode for saving a storage object with no substorages, the StgOpenStorageEx function accepts one of
+ /// the following two flag combinations as valid modes in the grfMode parameter:
+ ///
+ ///
+ /// To support the single-writer, multireader, direct mode, the first flag combination is the valid grfMode parameter for the writer.
+ /// The second flag combination is valid for readers.
+ ///
+ /// For more information about simple mode and single-writer/multiple-reader modes, see STGM Constants.
+ ///
+ /// Note Opening a transacted mode storage object in read and/or write mode without denying write permissions to others (for
+ /// example, the grfMode parameter specifies STGM_SHARE_DENY_WRITE) can be time-consuming because the StgOpenStorageEx
+ /// call must create a snapshot copy of the entire storage object.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgopenstorageex HRESULT StgOpenStorageEx( const WCHAR
+ // *pwcsName, DWORD grfMode, DWORD stgfmt, DWORD grfAttrs, STGOPTIONS *pStgOptions, PSECURITY_DESCRIPTOR pSecurityDescriptor, REFIID
+ // riid, void **ppObjectOpen );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "4f2138fb-1f80-4345-a3cb-9c11023457b1")]
+ public static extern HRESULT StgOpenStorageEx([In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pwcsName, STGM grfMode, STGFMT stgfmt, FileFlagsAndAttributes grfAttrs, in STGOPTIONS pStgOptions,
+ [Optional] PSECURITY_DESCRIPTOR pSecurityDescriptor, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 6)] out object ppObjectOpen);
+
+ ///
+ ///
+ /// The StgOpenStorageEx function opens an existing root storage object in the file system. Use this function to open Compound
+ /// Files and regular files. To create a new file, use the StgCreateStorageEx function.
+ ///
+ ///
+ /// Note To use enhancements, all Windows 2000, Windows XP, and Windows Server 2003 applications should call
+ /// StgOpenStorageEx, instead of StgOpenStorage. The StgOpenStorage function is used for compatibility with Windows
+ /// 2000 and earlier applications.
+ ///
+ ///
+ ///
+ ///
+ /// A pointer to the path of the null-terminated Unicode string file that contains the storage object. This string size cannot exceed
+ /// MAX_PATH characters.
+ ///
+ ///
+ /// Windows Server 2003 and Windows XP/2000: Unlike the CreateFile function, the MAX_PATH limit cannot be exceeded by
+ /// using the "\?" prefix.
+ ///
+ ///
+ ///
+ ///
+ /// A value that specifies the access mode to open the new storage object. For more information, see STGM Constants. If the caller
+ /// specifies transacted mode together with STGM_CREATE or STGM_CONVERT, the overwrite or conversion occurs when the
+ /// commit operation is called for the root storage. If IStorage::Commit is not called for the root storage object, previous contents
+ /// of the file will be restored. STGM_CREATE and STGM_CONVERT cannot be combined with the STGM_NOSNAPSHOT flag,
+ /// because a snapshot copy is required when a file is overwritten or converted in transacted mode.
+ ///
+ ///
+ /// If the storage object is opened in direct mode ( STGM_DIRECT) with access to either STGM_WRITE or
+ /// STGM_READWRITE, the sharing mode must be STGM_SHARE_EXCLUSIVE unless the STGM_DIRECT_SWMR mode is specified.
+ /// For more information, see the Remarks section. If the storage object is opened in direct mode with access to STGM_READ,
+ /// the sharing mode must be either STGM_SHARE_EXCLUSIVE or STGM_SHARE_DENY_WRITE, unless STGM_PRIORITY or
+ /// STGM_DIRECT_SWMR is specified. For more information, see the Remarks section.
+ ///
+ ///
+ /// The mode in which a file is opened can affect implementation performance. For more information, see Compound File Implementation Limits.
+ ///
+ ///
+ /// A value that specifies the storage file format. For more information, see the STGFMT enumeration.
+ ///
+ /// A value that depends upon the value of the stgfmt parameter.
+ ///
+ /// STGFMT_DOCFILE must be zero (0) or FILE_FLAG_NO_BUFFERING. For more information about this value, see CreateFile.
+ /// If the sector size of the file, specified in pStgOptions, is not an integer multiple of the physical sector size of the
+ /// underlying disk, then this operation will fail. All other values of stgfmt must be zero.
+ ///
+ ///
+ ///
+ /// A pointer to an STGOPTIONS structure that contains data about the storage object opened. The pStgOptions parameter is valid only
+ /// if the stgfmt parameter is set to STGFMT_DOCFILE. The usVersion member must be set before calling
+ /// StgOpenStorageEx. For more information, see the STGOPTIONS structure.
+ ///
+ /// Reserved; must be zero.
+ ///
+ /// A value that specifies the GUID of the interface pointer to return. Can also be the header-specified value for
+ /// IID_IStorage to obtain the IStorage interface or for IID_IPropertySetStorage to obtain the IPropertySetStorage interface.
+ ///
+ ///
+ /// The address of an interface pointer variable that receives a pointer for an interface on the storage object opened; contains
+ /// NULL if operation failed.
+ ///
+ ///
+ /// This function can also return any file system errors or system errors wrapped in an HRESULT. For more information, see
+ /// Error Handling Strategies and Handling Unknown Errors.
+ ///
+ ///
+ ///
+ /// StgOpenStorageEx is a superset of the StgOpenStorage function, and should be used by new code. Future enhancements to
+ /// structured storage will be exposed through this function. For more information about supported platforms, see the Requirements section.
+ ///
+ ///
+ /// The StgOpenStorageEx function opens the specified root storage object according to the access mode in the grfMode
+ /// parameter, and, if successful, supplies an interface pointer for the opened storage object in the ppObjectOpen parameter. This
+ /// function can be used to obtain an IStorage compound file implementation, an IPropertySetStorage compound file implementation, or
+ /// an NTFS file system implementation of IPropertySetStorage.
+ ///
+ ///
+ /// When you open a file, the system selects a structured storage implementation depending on which STGFMT flag you specify on the
+ /// file type and on the type of drive where the file is stored.
+ ///
+ ///
+ /// Use the StgOpenStorageEx function to access the root storage of a structured storage document or the property set storage
+ /// of any file that supports property sets. For more information about which interface identifiers (IIDs) are supported for the
+ /// different STGFMT values, see STGFMT.
+ ///
+ ///
+ /// When a file is opened with this function to access the NTFS property set implementation, special sharing rules apply. For more
+ /// information, see IPropertySetStorage-NTFS Implementation.
+ ///
+ ///
+ /// If a compound file is opened in transacted mode, by specifying STGM_TRANSACTED, and read-only mode, by specifying STGM_READ, it
+ /// is possible to change the returned storage object. For example, it is possible to call IStorage::CreateStream. However, it is not
+ /// possible to commit those changes by calling IStorage::Commit. Therefore, such changes will be lost.
+ ///
+ ///
+ /// It is not valid to use the STGM_CREATE, STGM_DELETEONRELEASE, or STGM_CONVERT flags in the grfMode parameter
+ /// for this function.
+ ///
+ ///
+ /// To support the simple mode for saving a storage object with no substorages, the StgOpenStorageEx function accepts one of
+ /// the following two flag combinations as valid modes in the grfMode parameter:
+ ///
+ ///
+ /// To support the single-writer, multireader, direct mode, the first flag combination is the valid grfMode parameter for the writer.
+ /// The second flag combination is valid for readers.
+ ///
+ /// For more information about simple mode and single-writer/multiple-reader modes, see STGM Constants.
+ ///
+ /// Note Opening a transacted mode storage object in read and/or write mode without denying write permissions to others (for
+ /// example, the grfMode parameter specifies STGM_SHARE_DENY_WRITE) can be time-consuming because the StgOpenStorageEx
+ /// call must create a snapshot copy of the entire storage object.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgopenstorageex HRESULT StgOpenStorageEx( const WCHAR
+ // *pwcsName, DWORD grfMode, DWORD stgfmt, DWORD grfAttrs, STGOPTIONS *pStgOptions, PSECURITY_DESCRIPTOR pSecurityDescriptor, REFIID
+ // riid, void **ppObjectOpen );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "4f2138fb-1f80-4345-a3cb-9c11023457b1")]
+ public static extern HRESULT StgOpenStorageEx([In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pwcsName, STGM grfMode, STGFMT stgfmt, FileFlagsAndAttributes grfAttrs, [Optional] IntPtr pStgOptions,
+ [Optional] PSECURITY_DESCRIPTOR pSecurityDescriptor, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 6)] out object ppObjectOpen);
+
+ ///
+ /// The StgOpenStorageOnILockBytes function opens an existing storage object that does not reside in a disk file, but instead
+ /// has an underlying byte array provided by the caller.
+ ///
+ /// ILockBytes pointer to the underlying byte array object that contains the storage object to be opened.
+ ///
+ ///
+ /// A pointer to the IStorage interface that should be NULL. If not NULL, this parameter is used as described below in
+ /// the Remarks section.
+ ///
+ ///
+ /// After StgOpenStorageOnILockBytes returns, the storage object specified in pStgPriority may have been released and should
+ /// no longer be used.
+ ///
+ ///
+ ///
+ /// Specifies the access mode to use to open the storage object. For more information, see STGM Constants and the Remarks section below.
+ ///
+ ///
+ /// Can be NULL. If not NULL, this parameter points to a block of elements in this storage that are to be excluded as
+ /// the storage object is opened. This exclusion occurs independently of whether a snapshot copy happens on the open.
+ ///
+ /// Indicates reserved for future use; must be zero.
+ /// Points to the location of an IStorage pointer to the opened storage on successful return.
+ ///
+ /// The StgOpenStorageOnILockBytes function can also return any file system errors, or system errors wrapped in an
+ /// HRESULT, or ILockBytes interface error return values. See Error Handling Strategies and Handling Unknown Errors.
+ ///
+ ///
+ ///
+ /// StgOpenStorageOnILockBytes opens the specified root storage object. A pointer to the IStorage interface on the opened
+ /// storage object is supplied through the ppstgOpen parameter.
+ ///
+ /// The storage object must have been previously created by the StgCreateDocfileOnILockBytes function.
+ ///
+ /// Except for specifying a programmer-provided byte-array object, StgOpenStorageOnILockBytes is similar to the StgOpenStorage
+ /// function. The storage object is opened according to the access modes in the grfMode parameter, subject to the following restrictions:
+ ///
+ ///
+ /// Sharing mode behavior and transactional isolation depend on the ILockBytes implementation supporting LockRegion and UnlockRegion
+ /// with LOCK_ONLYONCE semantics. Implementations can indicate to structured storage they support this functionality by setting the
+ /// LOCK_ONLYONCE bit in the grfLocksSupported member of STATSTG. If an ILockBytes implementation does not
+ /// support this functionality, sharing modes will not be enforced, and root-level transactional commits will not coordinate properly
+ /// with other transactional instances opened on the same byte array. Applications that use an ILockBytes implementation that
+ /// does not support region locking, such as the CreateStreamOnHGlobal implementation, should avoid opening multiple concurrent
+ /// instances on the same byte array.
+ ///
+ /// StgOpenStorageOnILockBytes does not support simple mode. The STGM_SIMPLE flag, if present, is ignored.
+ ///
+ /// The pStgPriority parameter is intended as a convenience for callers replacing an existing storage object, often one opened in
+ /// priority mode, with a new storage object opened on the same byte array. Unlike the pStgPriority parameter of StgOpenStorage, this
+ /// parameter does not affect the open operation performed by StgOpenStorageOnILockBytes and is simply an existing storage
+ /// object the caller would like released. Callers should always pass NULL for this parameter because
+ /// StgOpenStorageOnILockBytes releases the object under some circumstances, and does not release it under other
+ /// circumstances. The use of the pStgPriority parameter can be duplicated by the caller in a safer manner by instead releasing the
+ /// object before calling StgOpenStorageOnILockBytes, as shown in the following example:
+ ///
+ /// For more information, refer to StgOpenStorage.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgopenstorageonilockbytes HRESULT
+ // StgOpenStorageOnILockBytes( ILockBytes *plkbyt, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage
+ // **ppstgOpen );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "7920bd46-0a8f-42e0-9988-59d85edb64e2")]
+ public static extern HRESULT StgOpenStorageOnILockBytes([In] ILockBytes plkbyt, [In, Optional] IStorage pstgPriority, STGM grfMode, SNB snbExclude, [Optional] uint reserved, out IStorage ppstgOpen);
+
+ ///
+ /// The StgSetTimes function sets the creation, access, and modification times of the indicated file, if supported by the
+ /// underlying file system.
+ ///
+ /// Pointer to the name of the file to be changed.
+ /// Pointer to the new value for the creation time.
+ /// Pointer to the new value for the access time.
+ /// Pointer to the new value for the modification time.
+ ///
+ /// The StgSetTimes function can also return any file system errors or system errors wrapped in an HRESULT. See Error
+ /// Handling Strategies and Handling Unknown Errors.
+ ///
+ ///
+ ///
+ /// The StgSetTimes function sets the time values for the specified file. Each of the time value parameters can be
+ /// NULL, indicating that no modification should occur.
+ ///
+ ///
+ /// It is possible that one or more of these time values are not supported by the underlying file system. This function sets the
+ /// times that can be set and ignores the rest.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgsettimes HRESULT StgSetTimes( const WCHAR *lpszName,
+ // const FILETIME *pctime, const FILETIME *patime, const FILETIME *pmtime );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "5ade3e7a-a22a-458f-b463-1680893edc15")]
+ public static extern HRESULT StgSetTimes([In, MarshalAs(UnmanagedType.LPWStr)] string lpszName, in FILETIME pctime, in FILETIME patime, in FILETIME pmtime);
+
+ ///
+ /// The StgSetTimes function sets the creation, access, and modification times of the indicated file, if supported by the
+ /// underlying file system.
+ ///
+ /// Pointer to the name of the file to be changed.
+ /// Pointer to the new value for the creation time.
+ /// Pointer to the new value for the access time.
+ /// Pointer to the new value for the modification time.
+ ///
+ /// The StgSetTimes function can also return any file system errors or system errors wrapped in an HRESULT. See Error
+ /// Handling Strategies and Handling Unknown Errors.
+ ///
+ ///
+ ///
+ /// The StgSetTimes function sets the time values for the specified file. Each of the time value parameters can be
+ /// NULL, indicating that no modification should occur.
+ ///
+ ///
+ /// It is possible that one or more of these time values are not supported by the underlying file system. This function sets the
+ /// times that can be set and ignores the rest.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-stgsettimes HRESULT StgSetTimes( const WCHAR *lpszName,
+ // const FILETIME *pctime, const FILETIME *patime, const FILETIME *pmtime );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "5ade3e7a-a22a-458f-b463-1680893edc15")]
+ public static extern HRESULT StgSetTimes([In, MarshalAs(UnmanagedType.LPWStr)] string lpszName, [Optional] IntPtr pctime, [Optional] IntPtr patime, [Optional] IntPtr pmtime);
+
+ /// The WriteClassStg function stores the specified class identifier (CLSID) in a storage object.
+ /// IStorage pointer to the storage object that gets a new CLSID.
+ /// Pointer to the CLSID to be stored with the object.
+ /// This function returns HRESULT.
+ ///
+ /// The WriteClassStg function writes a CLSID to the specified storage object so that it can be read by the ReadClassStg
+ /// function. Container applications typically call this function before calling the IPersistStorage::Save method.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-writeclassstg HRESULT WriteClassStg( LPSTORAGE pStg,
+ // REFCLSID rclsid );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "5f2f16d1-923f-4ba7-8d4b-7e8535f6f15e")]
+ public static extern HRESULT WriteClassStg(IStorage pStg, in Guid rclsid);
+
+ /// The WriteClassStm function stores the specified CLSID in the stream.
+ /// IStream pointer to the stream into which the CLSID is to be written.
+ /// Specifies the CLSID to write to the stream.
+ /// This function returns HRESULT.
+ ///
+ /// The WriteClassStm function writes a CLSID to the specified stream object so it can be read by the ReadClassStm function.
+ /// Most applications do not call WriteClassStm directly. OLE calls it before making a call to an object's
+ /// IPersistStream::Save method.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/coml2api/nf-coml2api-writeclassstm HRESULT WriteClassStm( LPSTREAM pStm,
+ // REFCLSID rclsid );
+ [DllImport(Lib.Ole32, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("coml2api.h", MSDNShortId = "c08bfbc8-f7ac-4534-8c98-c732c6daa2f7")]
+ public static extern HRESULT WriteClassStm(IStream pStm, in Guid rclsid);
+ }
+}
\ No newline at end of file