- 
                Notifications
    You must be signed in to change notification settings 
- Fork 114
Description
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:
    public interface Interface : ISequentialStream.Interface
    {
        [VtblIndex(5)]
        HRESULT Seek(LARGE_INTEGER dlibMove, [NativeTypeName("DWORD")] uint dwOrigin, ULARGE_INTEGER* plibNewPosition);