-
Notifications
You must be signed in to change notification settings - Fork 94
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
Generate raw COM interface definitions to facilitate creating manual CCW #708
Comments
cc: @tannergooding |
You want to write this manually right now? Is there any further development you want to do on the idea before CsWin32 starts emitting this for you? Any thoughts on whether the interfaces use PreserveSig or not? The default in CsWin32 is to not use it except where prescribed by metadata or nativemethods.json file.
Is the fact that TerraFx uses a nested |
Yes, to vet the parts of CCW wrapping that are candidates for CsWin32 to generate. Want to be confident in implementation patterns.
I think it is ideal to match the native implementation to allow passing results without resorting to throwing and catching.
I don't think it is strictly necessary, but better allows aligning these definitions to CCW writing scenarios. |
It's interesting that in your own example (copied below) you don't show that. Below, the IStream interface's Read method either returns void or you discard the result anyway. Interop.Ole32.IStream instance = ComInterfaceDispatch.GetInstance<Interop.Ole32.IStream>((ComInterfaceDispatch*)thisPtr);
instance.Read(pv, cb, pcbRead);
return S_OK; If we were to actually use PreserveSig on these interfaces, it would look more like: Interop.Ole32.IStream instance = ComInterfaceDispatch.GetInstance<Interop.Ole32.IStream>((ComInterfaceDispatch*)thisPtr);
return instance.Read(pv, cb, pcbRead); In any case, I think for this request, I'll leave CsWin32 generating interfaces based on it's default behavior, and you can turn PreserveSig on wherever you want it via the .json file. |
Here is an example of how we want to implement a callback in a CCW: [UnmanagedCallersOnly]
private static HRESULT Load(IPersistStream* @this, IStream* pStm)
{
try
{
IPersistStream.Interface persistStream = GetManagedObject(@this);
return persistStream is null
? HRESULT.COR_E_OBJECTDISPOSED
: persistStream.Load(pStm);
}
catch (Exception ex)
{
return (HRESULT)ex.HResult;
}
} If the interface matches the vtable signatures (or possibly the helpful overloads in the struct) then code generating this sort of block becomes possible. |
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.
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
The text was updated successfully, but these errors were encountered: