smourier / DirectN

Direct interop Code for .NET Framework, .NET Core and .NET 5+ : DXGI, WIC, DirectX 9 to 12, Direct2D, Direct Write, Direct Composition, Media Foundation, WASAPI, CodecAPI, GDI, Spatial Audio, DVD, Windows Media Player, UWP DXInterop, WinUI3, etc.
MIT License
311 stars 28 forks source link

CreateDrawingStateBlock first paramater type why is nint ? #48

Closed sgf closed 9 months ago

sgf commented 9 months ago

image

same with image

smourier commented 9 months ago

(Please don't post images but raw text so search engines are effective)

Because this is how the COM interface method is designed in C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\d2d1.h:

STDMETHOD(CreateDrawingStateBlock)(
    _In_opt_ CONST D2D1_DRAWING_STATE_DESCRIPTION *drawingStateDescription,
    _In_opt_ IDWriteRenderingParams *textRenderingParams,
    _COM_Outptr_ ID2D1DrawingStateBlock **drawingStateBlock 
    ) PURE;

This corresponds to this method in MSDN: ID2D1Factory::CreateDrawingStateBlock(constD2D1_DRAWING_STATE_DESCRIPTION,IDWriteRenderingParams,ID2D1DrawingStateBlock**)

The other "methods" with the same name are not COM interface methods, but C++ function, "wrappers" compiled into the calling program, that we cannot call from .NET

COM_DECLSPEC_NOTHROW
HRESULT
CreateDrawingStateBlock(
    CONST D2D1_DRAWING_STATE_DESCRIPTION &drawingStateDescription,
    _COM_Outptr_ ID2D1DrawingStateBlock **drawingStateBlock 
    )  
{
    return CreateDrawingStateBlock(&drawingStateDescription, NULL, drawingStateBlock);
}

COM_DECLSPEC_NOTHROW
HRESULT
CreateDrawingStateBlock(
    _COM_Outptr_ ID2D1DrawingStateBlock **drawingStateBlock 
    )  
{
    return CreateDrawingStateBlock(NULL, NULL, drawingStateBlock);
}
sgf commented 9 months ago

I don't quite understand. The original functions you posted seem to be structure pointers. How should I convert the variables of the structure into nint as parameters?

smourier commented 9 months ago

The structure is a pointer because the parameter (a struct) is optional.

DirectN additionally add extension methods that wraps some methods call so they are easier to use. This is the case for ID2D1RenderTarget(but not for every COM interface and methods) in DirectN.ID2D1RenderTargetExtensions:

image

sgf commented 9 months ago

I also noticed the second overload before, but since it had too many parameters I neglected to select it. Thank you for your suggestion.