Skip to content

Generate raw COM interface definitions to facilitate creating manual CCW #708

@JeremyKuhne

Description

@JeremyKuhne

In manual generation of CCW's (using ComWrappers, for example) it would help to have interfaces defined that match the raw vtables so managed objects can implement for a generically written CCW to use.

A current example of this in WinForms is for IStream.

            [UnmanagedCallersOnly]
            private static int Read(IntPtr thisPtr, byte* pv, uint cb, uint* pcbRead)
            {
                try
                {
                    Interop.Ole32.IStream instance = ComInterfaceDispatch.GetInstance<Interop.Ole32.IStream>((ComInterfaceDispatch*)thisPtr);
                    instance.Read(pv, cb, pcbRead);
                    return S_OK;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                    return ex.HResult;
                }
            }

In the above example Interop.Ole32.IStream is what the CCW is written against. The blob above is pretty generic and could easily be added to code generation in CsWin32 in the future (as an option). In the immediate term we want to write this manually using interfaces CsWin32 defines. If they are written as normal interfaces with matching inheritance (IStream : ISequentialStream : IUnknown) it would allow sharing of code generated for CCWs.

The pattern TerraFx uses for COM is the ideal we're looking for:

https://github.com/terrafx/terrafx.interop.windows/blob/main/sources/Interop/Windows/Windows/um/objidlbase/IStream.cs#L137

    public interface Interface : ISequentialStream.Interface
    {
        [VtblIndex(5)]
        HRESULT Seek(LARGE_INTEGER dlibMove, [NativeTypeName("DWORD")] uint dwOrigin, ULARGE_INTEGER* plibNewPosition);

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions