Closed sgf closed 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);
}
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?
The structure is a pointer because the parameter (a struct) is optional.
drawingStateDescription
, then just pass IntPtr.Zero
for the drawingStateDescription
parameter. If you want to pass a structure, you must allocate a buffer of structure size and marshal the .NET structure to the allocated buffer. But DirectN has a ComMemory
utility to help you do that easily:
var desc = new D2D1_DRAWING_STATE_DESCRIPTION();
desc.antialiasMode = D2D1_ANTIALIAS_MODE.D2D1_ANTIALIAS_MODE_ALIASED;
// etc...
ID2D1Factory fac = ...
using (var mem = new ComMemory(desc))
{
fac.CreateDrawingStateBlock(mem.Pointer, etc ...);
}
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
:
I also noticed the second overload before, but since it had too many parameters I neglected to select it. Thank you for your suggestion.
same with![image](https://github.com/smourier/DirectN/assets/2557696/4150cc91-753c-4b55-a8c9-3383b8c05dc5)