Jump to content
pyscripter

Translation of C headers.

Recommended Posts

20 minutes ago, Mahdi Safsafi said:

Those are not stored inside vtable ... you need to skip them(don't declare them).

Exactly! 

That's my bad man ... I'm a little bit bad at explaining since I'm not a native English speaker.

First step, add all methods in the order they declared(skip all overloaded versions but keep the original). second step for each added method "A" add just after it "A" all its overloaded versions in the order they declared too.

Here is how your vtable looks like.

 

vtbl.PNG

The functions seem to work now (Succeeded) but still no recoloring though).

What is strange is that the order of the overloads in the VTable is the reverse than that in the include file.  

What is the tool you are using to inspect the Vtables?

Share this post


Link to post

@pyscripter d2missing again without the reformatting, sorry 😉

D2DMissing.7z

 

btw. he is using IDA

 

btw2. RecolorSubtree(Root, D2D1ColorF(1, 0, 0, 0)); should be the other way, 0,0,0,1, rgba

Edited by Attila Kovacs

Share this post


Link to post
Guest

This is the right order as Mahdi shown and this will recolor and get the Paint item right, @Attila Kovacs your last file still reversed.

Quote

    function SetAttributeValue(name: LPWSTR;
                               value: ID2D1SvgAttribute): HResult; overload; stdcall;
    function SetAttributeValue(name: LPWSTR;
                               _type: D2D1_SVG_ATTRIBUTE_POD_TYPE;
                               value: Pointer;
                               valueSizeInBytes: UINT32): HResult; overload; stdcall;
     function SetAttributeValue(name: LPWSTR;
                               _type: D2D1_SVG_ATTRIBUTE_STRING_TYPE;
                               value: LPWSTR): HResult; overload; stdcall;


    function GetAttributeValue(name: LPWSTR;
                               const riid: TGUID;
                               var value: Pointer): HResult; overload; stdcall;

    function GetAttributeValue(name: LPWSTR;
                               _type: D2D1_SVG_ATTRIBUTE_POD_TYPE;
                               value: Pointer;
                               valueSizeInBytes: UINT32): HResult; overload; stdcall;
    function GetAttributeValue(name: LPWSTR;
                               _type: D2D1_SVG_ATTRIBUTE_STRING_TYPE;
                               out value: PWideChar;
                               valueCount: UINT32): HResult; overload; stdcall;

 

Share this post


Link to post

@Kas Ob. your version AV's here, I get the recoloring 😄 what now

 

hm, sorry, it works, so declare in reverse order?

 

image.png.66c8f571a550463e6727f8f7b260b98a.png

Edited by Attila Kovacs

Share this post


Link to post

@Kas Ob.order which is the same as shown by IDA works here.  I can recolor both ways:

 

    if Succeeded(Element.GetAttributeValue('fill', D2D1_SVG_ATTRIBUTE_POD_TYPE_COLOR,
       @OldColor, SizeOf(OldColor)))
     then
     begin
       if (OldColor.r <> 0) or (OldColor.g <> 0) or (OldColor.b <> 0)  then
         Assert(Succeeded(Element.SetAttributeValue('fill', D2D1_SVG_ATTRIBUTE_POD_TYPE_COLOR,
           @NewColor, SizeOf(NewColor))));
     end;

and

 

    Assert(Succeeded(Element.GetAttributeValue('fill', IID_ID2D1SvgPaint, Pointer(Paint))));
    if Assigned(Paint) then begin
      Paint._AddRef;
      if Paint.GetPaintType = D2D1_SVG_PAINT_TYPE_COLOR then
      begin
        Paint.GetColor(OldColor);
        if (OldColor.r <> 0) or (OldColor.g <> 0) or (OldColor.b <> 0)  then
          Paint.SetColor(NewColor);
      end;
    end;
  end;

The declaration of SetColor needs to be changed:

 

 

  function SetColor(Const color: D2D1_COLOR_F): HResult; stdcall;

 

Edited by pyscripter

Share this post


Link to post

@Attila Kovacs

RecolorSubtree(Root, D2D1ColorF(0.5, 80, 80, 80)); 

does not make sense

The Values need to be between 0 and 1 for instance.

D2D1ColorF(clRed) = D2D1ColorF(1,0,0,1)

 

I will doing drawing in GrayScale.

Does anyone know how to draw the svg with opacity say 0.5?  Everything not just the fill color possibly using D2D primitives?

 

Edited by pyscripter

Share this post


Link to post

@pyscripter yup, was just playing around, it's also RGBA so the original 1, 0, 0, 0 did also not make much sense, mentioned that already earlier

Edited by Attila Kovacs

Share this post


Link to post
18 minutes ago, pyscripter said:

Does anyone know how to draw the svg with opacity say 0.5?  Everything not just the fill color possibly using D2D primitives?

      opacity : single := 0.5;
      Element.SetAttributeValue('opacity', D2D1_SVG_ATTRIBUTE_POD_TYPE_FLOAT, @opacity, SizeOf(opacity));
      where element = 'svg'

 

 if this was the question

  • Thanks 1

Share this post


Link to post
7 minutes ago, Attila Kovacs said:

Element.SetAttributeValue('opacity', D2D1_SVG_ATTRIBUTE_POD_TYPE_FLOAT, @opacity, SizeOf(opacity));

If you do it on the Root it works as expected.

Share this post


Link to post

btw. in the header and also on the screenshot from Mahdi the first parameters are PCWSTR (LPCWSTR) (const) and not always PWSTR (LPWSTR).

this however makes no difference, at least at the moment, as they are defined the same in delphi 

Edited by Attila Kovacs
  • Like 1

Share this post


Link to post
20 minutes ago, Attila Kovacs said:

btw. in the header and also on the screenshot from Mahdi the first parameters are PCWSTR (LPCWSTR) (const) and not always PWSTR (LPWSTR).

this however makes no difference, at least at the moment, as they are defined the same in delphi 

Good point Attila. It also makes comparing c code against Delphi code much easy. 

Share this post


Link to post

@pyscripter

Did you run the original example from Microsoft in Visual Studio?

 

Share this post


Link to post

Well after I had a discussion with Microsoft, we came to some conclusions:
First of all: The original declaration of ID2D1SvgElement is probably correct!
Changing the method order results in multiple errors using the original Microsoft D2DSvgImage sample (with some changes concerning the use of inline functions).
The problem probably hints to a wrong D2D1 initialization sequence.
For instance: SetAttributeValue should be called before GetAttributeValue at any time!
If nothing is set there is nothing to get! And therefore results to a Nil and hresult is 'The parameter is incorrect.'

If you want a color, you shuold use the ID2D1SvgPaint interface to retrieve a color, not ID2D1SvgElement.GetAttributeValue!
We did an experiment to alter the header as suggested by Pyscripter and run it in VS2019.. Well, that wented out to be a disaster: The MS sample did not work anymore.
Most likely the thing is: The Delphi samples (about svg here) are bogus.
We wil investigate this issue further on, but until now it points to a wrong usage/implenentation of D2D1.

 

About the Vtable: The correct Vtable should be showed in memory, not by decompiling a dll.

 

 

 

Edited by maXcomX

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×