Skip to content

Commit

Permalink
Add coml2api.h
Browse files Browse the repository at this point in the history
This adds all of the Structured Stroage (IStorage) related APIs and related defines.

Add the remap-classes.rsp to the solution file.

fixes terrafx#263
fixes terrafx#227
  • Loading branch information
JeremyKuhne committed Dec 1, 2021
1 parent ea649a6 commit 3227357
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 0 deletions.
9 changes: 9 additions & 0 deletions TerraFX.Interop.Windows.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{8793898A-6
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "generation", "generation", "{D9638FEE-50A4-44FF-B1F6-72E59548490B}"
ProjectSection(SolutionItems) = preProject
generation\remap-classes.rsp = generation\remap-classes.rsp
generation\remap-guids.rsp = generation\remap-guids.rsp
generation\remap-handles.rsp = generation\remap-handles.rsp
generation\remap-members.rsp = generation\remap-members.rsp
Expand Down Expand Up @@ -2685,6 +2686,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "errhandlingapi", "errhandli
generation\Windows\um\errhandlingapi\um-errhandlingapi.h = generation\Windows\um\errhandlingapi\um-errhandlingapi.h
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "coml2api", "coml2api", "{62D8ADD9-4B4F-45FF-BAF1-C48A77A0F861}"
ProjectSection(SolutionItems) = preProject
generation\Windows\um\coml2api\generate.rsp = generation\Windows\um\coml2api\generate.rsp
generation\Windows\um\coml2api\header.txt = generation\Windows\um\coml2api\header.txt
generation\Windows\um\coml2api\um-coml2api.h = generation\Windows\um\coml2api\um-coml2api.h
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -3100,6 +3108,7 @@ Global
{E861DAD6-1605-417F-9850-2CB8BDFFA53A} = {67311E5E-FA9C-43A6-B431-9EF10047A0CE}
{73647067-4ED1-478A-BD13-8E9DB203BAC9} = {67311E5E-FA9C-43A6-B431-9EF10047A0CE}
{6783A12A-BC19-47EA-A006-2D856681241E} = {67311E5E-FA9C-43A6-B431-9EF10047A0CE}
{62D8ADD9-4B4F-45FF-BAF1-C48A77A0F861} = {67311E5E-FA9C-43A6-B431-9EF10047A0CE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2FE36DF8-2D9C-4F20-8787-45DC74B57461}
Expand Down
16 changes: 16 additions & 0 deletions generation/Windows/um/coml2api/generate.rsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@../../../settings.rsp
@../../../remap.rsp
--file
um-coml2api.h
--methodClassName
Windows
--namespace
TerraFX.Interop.Windows
--output
../../../../sources/Interop/Windows/Windows/um/coml2api
--test-output
../../../../tests/Interop/Windows/Windows/um/coml2api
--traverse
C:/Program Files (x86)/Windows Kits/10/Include/10.0.20348.0/um/coml2api.h
--with-librarypath
*=ole32
4 changes: 4 additions & 0 deletions generation/Windows/um/coml2api/header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

// Ported from um/coml2api.h in the Windows SDK for Windows 10.0.20348.0
// Original source is Copyright © Microsoft. All rights reserved.
2 changes: 2 additions & 0 deletions generation/Windows/um/coml2api/um-coml2api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "..\..\..\TerraFX.h"
#include <coml2api.h>
2 changes: 2 additions & 0 deletions generation/remap-classes.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ STATE_*=STATE
STATUS_*=STATUS
STD_*=STD
STG_*=STG
STGFMT_*=STGFMT
STGM_*=STGM
STORAGE_*=STORAGE
STREAM_*=STREAM
STR_*=STR
Expand Down
27 changes: 27 additions & 0 deletions sources/Interop/Windows/Windows/um/coml2api/STGFMT.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

// Ported from um/coml2api.h in the Windows SDK for Windows 10.0.20348.0
// Original source is Copyright © Microsoft. All rights reserved.

namespace TerraFX.Interop.Windows;

public static partial class STGFMT
{
[NativeTypeName("#define STGFMT_STORAGE 0")]
public const int STGFMT_STORAGE = 0;

[NativeTypeName("#define STGFMT_NATIVE 1")]
public const int STGFMT_NATIVE = 1;

[NativeTypeName("#define STGFMT_FILE 3")]
public const int STGFMT_FILE = 3;

[NativeTypeName("#define STGFMT_ANY 4")]
public const int STGFMT_ANY = 4;

[NativeTypeName("#define STGFMT_DOCFILE 5")]
public const int STGFMT_DOCFILE = 5;

[NativeTypeName("#define STGFMT_DOCUMENT 0")]
public const int STGFMT_DOCUMENT = 0;
}
63 changes: 63 additions & 0 deletions sources/Interop/Windows/Windows/um/coml2api/STGM.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

// Ported from um/coml2api.h in the Windows SDK for Windows 10.0.20348.0
// Original source is Copyright © Microsoft. All rights reserved.

namespace TerraFX.Interop.Windows;

public static partial class STGM
{
[NativeTypeName("#define STGM_DIRECT 0x00000000L")]
public const int STGM_DIRECT = 0x00000000;

[NativeTypeName("#define STGM_TRANSACTED 0x00010000L")]
public const int STGM_TRANSACTED = 0x00010000;

[NativeTypeName("#define STGM_SIMPLE 0x08000000L")]
public const int STGM_SIMPLE = 0x08000000;

[NativeTypeName("#define STGM_READ 0x00000000L")]
public const int STGM_READ = 0x00000000;

[NativeTypeName("#define STGM_WRITE 0x00000001L")]
public const int STGM_WRITE = 0x00000001;

[NativeTypeName("#define STGM_READWRITE 0x00000002L")]
public const int STGM_READWRITE = 0x00000002;

[NativeTypeName("#define STGM_SHARE_DENY_NONE 0x00000040L")]
public const int STGM_SHARE_DENY_NONE = 0x00000040;

[NativeTypeName("#define STGM_SHARE_DENY_READ 0x00000030L")]
public const int STGM_SHARE_DENY_READ = 0x00000030;

[NativeTypeName("#define STGM_SHARE_DENY_WRITE 0x00000020L")]
public const int STGM_SHARE_DENY_WRITE = 0x00000020;

[NativeTypeName("#define STGM_SHARE_EXCLUSIVE 0x00000010L")]
public const int STGM_SHARE_EXCLUSIVE = 0x00000010;

[NativeTypeName("#define STGM_PRIORITY 0x00040000L")]
public const int STGM_PRIORITY = 0x00040000;

[NativeTypeName("#define STGM_DELETEONRELEASE 0x04000000L")]
public const int STGM_DELETEONRELEASE = 0x04000000;

[NativeTypeName("#define STGM_NOSCRATCH 0x00100000L")]
public const int STGM_NOSCRATCH = 0x00100000;

[NativeTypeName("#define STGM_CREATE 0x00001000L")]
public const int STGM_CREATE = 0x00001000;

[NativeTypeName("#define STGM_CONVERT 0x00020000L")]
public const int STGM_CONVERT = 0x00020000;

[NativeTypeName("#define STGM_FAILIFTHERE 0x00000000L")]
public const int STGM_FAILIFTHERE = 0x00000000;

[NativeTypeName("#define STGM_NOSNAPSHOT 0x00200000L")]
public const int STGM_NOSNAPSHOT = 0x00200000;

[NativeTypeName("#define STGM_DIRECT_SWMR 0x00400000L")]
public const int STGM_DIRECT_SWMR = 0x00400000;
}
24 changes: 24 additions & 0 deletions sources/Interop/Windows/Windows/um/coml2api/STGOPTIONS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

// Ported from um/coml2api.h in the Windows SDK for Windows 10.0.20348.0
// Original source is Copyright © Microsoft. All rights reserved.

namespace TerraFX.Interop.Windows;

/// <include file='STGOPTIONS.xml' path='doc/member[@name="STGOPTIONS"]/*' />
public unsafe partial struct STGOPTIONS
{
/// <include file='STGOPTIONS.xml' path='doc/member[@name="STGOPTIONS.usVersion"]/*' />
public ushort usVersion;

/// <include file='STGOPTIONS.xml' path='doc/member[@name="STGOPTIONS.reserved"]/*' />
public ushort reserved;

/// <include file='STGOPTIONS.xml' path='doc/member[@name="STGOPTIONS.ulSectorSize"]/*' />
[NativeTypeName("ULONG")]
public uint ulSectorSize;

/// <include file='STGOPTIONS.xml' path='doc/member[@name="STGOPTIONS.pwcsTemplateFile"]/*' />
[NativeTypeName("const WCHAR *")]
public ushort* pwcsTemplateFile;
}
105 changes: 105 additions & 0 deletions sources/Interop/Windows/Windows/um/coml2api/Windows.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

// Ported from um/coml2api.h in the Windows SDK for Windows 10.0.20348.0
// Original source is Copyright © Microsoft. All rights reserved.

using System;
using System.Runtime.InteropServices;

namespace TerraFX.Interop.Windows;

public static unsafe partial class Windows
{
/// <include file='Windows.xml' path='doc/member[@name="Windows.StgCreateDocfile"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT StgCreateDocfile([NativeTypeName("const WCHAR *")] ushort* pwcsName, [NativeTypeName("DWORD")] uint grfMode, [NativeTypeName("DWORD")] uint reserved, IStorage** ppstgOpen);

/// <include file='Windows.xml' path='doc/member[@name="Windows.StgCreateDocfileOnILockBytes"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT StgCreateDocfileOnILockBytes(ILockBytes* plkbyt, [NativeTypeName("DWORD")] uint grfMode, [NativeTypeName("DWORD")] uint reserved, IStorage** ppstgOpen);

/// <include file='Windows.xml' path='doc/member[@name="Windows.StgOpenStorage"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT StgOpenStorage([NativeTypeName("const WCHAR *")] ushort* pwcsName, IStorage* pstgPriority, [NativeTypeName("DWORD")] uint grfMode, [NativeTypeName("SNB")] ushort** snbExclude, [NativeTypeName("DWORD")] uint reserved, IStorage** ppstgOpen);

/// <include file='Windows.xml' path='doc/member[@name="Windows.StgOpenStorageOnILockBytes"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT StgOpenStorageOnILockBytes(ILockBytes* plkbyt, IStorage* pstgPriority, [NativeTypeName("DWORD")] uint grfMode, [NativeTypeName("SNB")] ushort** snbExclude, [NativeTypeName("DWORD")] uint reserved, IStorage** ppstgOpen);

/// <include file='Windows.xml' path='doc/member[@name="Windows.StgIsStorageFile"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT StgIsStorageFile([NativeTypeName("const WCHAR *")] ushort* pwcsName);

/// <include file='Windows.xml' path='doc/member[@name="Windows.StgIsStorageILockBytes"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT StgIsStorageILockBytes(ILockBytes* plkbyt);

/// <include file='Windows.xml' path='doc/member[@name="Windows.StgSetTimes"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT StgSetTimes([NativeTypeName("const WCHAR *")] ushort* lpszName, [NativeTypeName("const FILETIME *")] FILETIME* pctime, [NativeTypeName("const FILETIME *")] FILETIME* patime, [NativeTypeName("const FILETIME *")] FILETIME* pmtime);

/// <include file='Windows.xml' path='doc/member[@name="Windows.StgCreateStorageEx"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT StgCreateStorageEx([NativeTypeName("const WCHAR *")] ushort* pwcsName, [NativeTypeName("DWORD")] uint grfMode, [NativeTypeName("DWORD")] uint stgfmt, [NativeTypeName("DWORD")] uint grfAttrs, STGOPTIONS* pStgOptions, [NativeTypeName("PSECURITY_DESCRIPTOR")] void* pSecurityDescriptor, [NativeTypeName("const IID &")] Guid* riid, void** ppObjectOpen);

/// <include file='Windows.xml' path='doc/member[@name="Windows.StgOpenStorageEx"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT StgOpenStorageEx([NativeTypeName("const WCHAR *")] ushort* pwcsName, [NativeTypeName("DWORD")] uint grfMode, [NativeTypeName("DWORD")] uint stgfmt, [NativeTypeName("DWORD")] uint grfAttrs, STGOPTIONS* pStgOptions, [NativeTypeName("PSECURITY_DESCRIPTOR")] void* pSecurityDescriptor, [NativeTypeName("const IID &")] Guid* riid, void** ppObjectOpen);

/// <include file='Windows.xml' path='doc/member[@name="Windows.StgCreatePropStg"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT StgCreatePropStg(IUnknown* pUnk, [NativeTypeName("const IID &")] Guid* fmtid, [NativeTypeName("const CLSID *")] Guid* pclsid, [NativeTypeName("DWORD")] uint grfFlags, [NativeTypeName("DWORD")] uint dwReserved, IPropertyStorage** ppPropStg);

/// <include file='Windows.xml' path='doc/member[@name="Windows.StgOpenPropStg"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT StgOpenPropStg(IUnknown* pUnk, [NativeTypeName("const IID &")] Guid* fmtid, [NativeTypeName("DWORD")] uint grfFlags, [NativeTypeName("DWORD")] uint dwReserved, IPropertyStorage** ppPropStg);

/// <include file='Windows.xml' path='doc/member[@name="Windows.StgCreatePropSetStg"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT StgCreatePropSetStg(IStorage* pStorage, [NativeTypeName("DWORD")] uint dwReserved, IPropertySetStorage** ppPropSetStg);

/// <include file='Windows.xml' path='doc/member[@name="Windows.FmtIdToPropStgName"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT FmtIdToPropStgName([NativeTypeName("const FMTID *")] Guid* pfmtid, [NativeTypeName("LPOLESTR")] ushort* oszName);

/// <include file='Windows.xml' path='doc/member[@name="Windows.PropStgNameToFmtId"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT PropStgNameToFmtId([NativeTypeName("const LPOLESTR")] ushort* oszName, [NativeTypeName("FMTID *")] Guid* pfmtid);

/// <include file='Windows.xml' path='doc/member[@name="Windows.ReadClassStg"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT ReadClassStg([NativeTypeName("LPSTORAGE")] IStorage* pStg, [NativeTypeName("CLSID *")] Guid* pclsid);

/// <include file='Windows.xml' path='doc/member[@name="Windows.WriteClassStg"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT WriteClassStg([NativeTypeName("LPSTORAGE")] IStorage* pStg, [NativeTypeName("const IID &")] Guid* rclsid);

/// <include file='Windows.xml' path='doc/member[@name="Windows.ReadClassStm"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT ReadClassStm([NativeTypeName("LPSTREAM")] IStream* pStm, [NativeTypeName("CLSID *")] Guid* pclsid);

/// <include file='Windows.xml' path='doc/member[@name="Windows.WriteClassStm"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT WriteClassStm([NativeTypeName("LPSTREAM")] IStream* pStm, [NativeTypeName("const IID &")] Guid* rclsid);

/// <include file='Windows.xml' path='doc/member[@name="Windows.GetHGlobalFromILockBytes"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT GetHGlobalFromILockBytes([NativeTypeName("LPLOCKBYTES")] ILockBytes* plkbyt, HGLOBAL* phglobal);

/// <include file='Windows.xml' path='doc/member[@name="Windows.CreateILockBytesOnHGlobal"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT CreateILockBytesOnHGlobal(HGLOBAL hGlobal, BOOL fDeleteOnRelease, [NativeTypeName("LPLOCKBYTES *")] ILockBytes** pplkbyt);

/// <include file='Windows.xml' path='doc/member[@name="Windows.GetConvertStg"]/*' />
[DllImport("ole32", ExactSpelling = true)]
public static extern HRESULT GetConvertStg([NativeTypeName("LPSTORAGE")] IStorage* pStg);

[NativeTypeName("#define CWCSTORAGENAME 32")]
public const int CWCSTORAGENAME = 32;

[NativeTypeName("#define STGOPTIONS_VERSION 2")]
public const int STGOPTIONS_VERSION = 2;

[NativeTypeName("#define CCH_MAX_PROPSTG_NAME 31")]
public const int CCH_MAX_PROPSTG_NAME = 31;
}
42 changes: 42 additions & 0 deletions tests/Interop/Windows/Windows/um/coml2api/STGOPTIONSTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

// Ported from um/coml2api.h in the Windows SDK for Windows 10.0.20348.0
// Original source is Copyright © Microsoft. All rights reserved.

using NUnit.Framework;
using System;
using System.Runtime.InteropServices;

namespace TerraFX.Interop.Windows.UnitTests;

/// <summary>Provides validation of the <see cref="STGOPTIONS" /> struct.</summary>
public static unsafe partial class STGOPTIONSTests
{
/// <summary>Validates that the <see cref="STGOPTIONS" /> struct is blittable.</summary>
[Test]
public static void IsBlittableTest()
{
Assert.That(Marshal.SizeOf<STGOPTIONS>(), Is.EqualTo(sizeof(STGOPTIONS)));
}

/// <summary>Validates that the <see cref="STGOPTIONS" /> struct has the right <see cref="LayoutKind" />.</summary>
[Test]
public static void IsLayoutSequentialTest()
{
Assert.That(typeof(STGOPTIONS).IsLayoutSequential, Is.True);
}

/// <summary>Validates that the <see cref="STGOPTIONS" /> struct has the correct size.</summary>
[Test]
public static void SizeOfTest()
{
if (Environment.Is64BitProcess)
{
Assert.That(sizeof(STGOPTIONS), Is.EqualTo(16));
}
else
{
Assert.That(sizeof(STGOPTIONS), Is.EqualTo(12));
}
}
}

0 comments on commit 3227357

Please sign in to comment.