fanc999 / d2d-sample-mostly-c

Mostly C port of Microsoft's Simple Direct2D tutorial
6 stars 1 forks source link

Reguarding the ID2D1HwndRenderTarget::GetSize issue you mentioned. #1

Open jacoblusk opened 2 years ago

jacoblusk commented 2 years ago

Hello,

I had found your repository and saw you mentioning some issues with ID2D1HwndRenderTarget::GetSize in C. I noticed a probably similar problem with GetPixelSize and I wrote this to fix it, basically instead of returning the size, you should be passing a out pointer as the 2nd argument.

I ran into this problem when I was working with GCC, I haven't tried it on MSVC yet though so if you are let me know if it works!

typedef VOID (* fnID2D1HwndRenderTarget_GetPixelSize) (ID2D1RenderTarget *, D2D1_SIZE_U *);
VOID ID2D1HwndRenderTarget_GetPixelSizeFix(ID2D1HwndRenderTarget *this, D2D1_SIZE_U *puSize) {
    fnID2D1HwndRenderTarget_GetPixelSize fnGetPixelSize = (fnID2D1HwndRenderTarget_GetPixelSize) ((ID2D1RenderTarget *)this)->lpVtbl->GetPixelSize;
    (*fnGetPixelSize)((ID2D1RenderTarget *)this, puSize);
}
ybop commented 5 months ago

I know this is ancient but just to add my 2 cents... I independently discovered that changing the definition of ID2D1HwndRenderTarget_GetSize to add a pointer to the size as the 2nd argument, worked! So there is no longer any need for any cpp files at all! Most likely any other function with a similar problem will have a similar solution. But it's sad that microsoft decided to deprecate and then remove these C accessible functions to it will only work with an old SDK.