Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Source Generator Generates Structs Instead of Interfaces #52

Closed
v-alje opened this issue Jan 22, 2021 · 1 comment
Closed

Source Generator Generates Structs Instead of Interfaces #52

v-alje opened this issue Jan 22, 2021 · 1 comment

Comments

@v-alje
Copy link
Member

v-alje commented Jan 22, 2021

The source generator currently generates structs instead of interfaces. This makes things a little difficult when an API relies on being able to use inheritance and multiple interfaces, for example DWriteCreateFactory:

NativeMethods.txt

DWRITE.*
IUnknown
IDWriteFactory
IDWriteFactory1
IDWriteFactory2
IDWriteFactory3
IDWriteFactory4
IDWriteFactory5
IDWriteFactory6
IDWriteFactory7

Program.cs

using Microsoft.Windows.Sdk;

namespace InterFaceGenerationRepro
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            IDWriteFactory factory;
            HRESULT result = PInvoke.DWriteCreateFactory(DWRITE_FACTORY_TYPE.DWRITE_FACTORY_TYPE_SHARED, typeof(IDWriteFactory).GUID, out factory);
        }
    }
}

The IDWriteFactory interface is based off of IUnknown, and has seven other interfaces that can be swapped in to provide additional methods that can be called, by changing the GUID in the DWriteCreateFactory iid parameter to communicate which interface to use.

Expected:
The source generator should generate interfaces with full inheritance hierarchy for interfaces.

Actual:
The source generator currently generates structs in place of interfaces, causing DWriteCreateFactory's factory out parameter to not be able to cast to any of the IDWriteFactory interfaces to the defined IUnknown type.

@AArnott
Copy link
Member

AArnott commented Jan 22, 2021

Thanks for the feedback. The current behavior is intentional but we want to offer interface generation as an option.
Once we get into interfaces, marshaling of structs is required, which unravels a bunch of the rest of the generated code. We do want to do this as an option variant of code gen.

Duplicate of #26

@AArnott AArnott closed this as completed Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants