Open DJm00n opened 2 years ago
The way I read the docs for this API, we see that c
is defined to be:
The length of the string pointed to by lpString.
So we know c == lpString.Length
. But reading on...
For the ANSI version of ExtTextOut, the lpDx array has the same number of INT values as there are bytes in lpString. For DBCS characters, you can apportion the dx in the lpDx entries between the lead byte and the trail byte, as long as the sum of the two bytes adds up to the desired dx. For DBCS characters with the Unicode version of ExtTextOut, each Unicode glyph gets a single pdx entry.
We see that lpDx
is tied to the length of lpString
. That means by the transitive property, that c
can be derived from the length of either lpString
or lpDx
because they are supposed to be equal. In fact this is what the underlying metadata for the API suggests as well:
public unsafe static extern BOOL ExtTextOutW([In] HDC hdc, [In] int x, [In] int y, [In] ETO_OPTIONS options, [Optional][In][Const] RECT lprect, [Optional][In][Const][NativeArrayInfo(CountParamIndex = 6)] PWSTR lpString, [In] uint c, [Optional][In][Const][NativeArrayInfo(CountParamIndex = 6)] int lpDx)
We could improve the wrapper to throw in such a case if the two arguments don't have equal lengths to help make this more clear, but I don't think we'll get around to that.
Thank you @AArnott!
Seems that API is a bit more trickery than I thought. But I still didn’t get how to call current wrapper properly in case when I want to omit lpDx
.
Ooh! Good point. I see from the docs that lpDx
is:
A pointer to an optional array of values
I'll have to review to see how we can best accommodate this.
Actual behavior
Seems CsWin32 generates ReadOnlySpan where it should't: I seening
string lpString, ReadOnlySpan<int> lpDx
where in original there iswinmdroot.Foundation.PCWSTR lpString, uint c, [Optional] int* lpDx
where c isThe length of the string pointed to by lpString.
but it get receives(uint )lpDx.Length
in wrapper instead.Expected behavior
uint c
andint* lpDx
should have separate parameters in generatedExtTextOut
wrapper.Repro steps
NativeMethods.txt
content:NativeMethods.json
content:Context
net461;net472;netcoreapp3.1
LangVersion
(if explicitly set by project):9.0