Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 546
  • Last Modified:

c++ to Delphi (Part of VNC code)

OK. This has had me stumped all weekend. I am working on a partial conversion of the vnchooks.cpp file to delphi. I am looking at the code that handles the WM_PAINT message and am getting stumped on some pointer arithmetic.


As you can see, i've pretty much got it all comvertied, but I'm stuck on one line..  Hope somebody can help!

Heres the c++:
inline BOOL HookHandle(UINT MessageId, HWND hWnd, WPARAM wParam, LPARAM lParam)
{

      switch (MessageId)
      {
case WM_PAINT:
            if (prf_use_GetUpdateRect)
            {
                  HRGN region;
                  region = CreateRectRgn(0, 0, 0, 0);

                  // Get the affected region
                  if (GetUpdateRgn(hWnd, region, FALSE) != ERROR)
                  {
                        int buffsize;
                        UINT x;
                        RGNDATA *buff;
                        POINT TopLeft;

                        // Get the top-left point of the client area
                        TopLeft.x = 0;
                        TopLeft.y = 0;
                        if (!ClientToScreen(hWnd, &TopLeft))
                              break;

                        // Get the size of buffer required
                        buffsize = GetRegionData(region, 0, 0);
                        if (buffsize != 0)
                        {
                              buff = (RGNDATA *) new BYTE [buffsize];
                              if (buff == NULL)
                                    break;

                              // Now get the region data
                              if(GetRegionData(region, buffsize, buff))
                              {
                                    for (x=0; x<(buff->rdh.nCount); x++)
                                    {
                                          // Obtain the rectangles from the list
                                          RECT *urect = (RECT *) (((BYTE *) buff) + sizeof(RGNDATAHEADER) + (x * sizeof(RECT)));
                                          SendDeferredUpdateRect(
                                                hWnd,
                                                (SHORT) (TopLeft.x + urect->left),
                                                (SHORT) (TopLeft.y + urect->top),
                                                (SHORT) (TopLeft.x + urect->right),
                                                (SHORT) (TopLeft.y + urect->bottom)
                                                );
                                    }
                              }

                              delete [] buff;
                        }
                  }

                  // Now free the region
                  if (region != NULL)
                        DeleteObject(region);
            }
  }
Return True;
}



Heres what I've got so far:

function HookHandle(MessageID:Cardinal; hW:HWND; WPARAM: wParam; LPARAM: lParam): LResult;
var x:Integer;
  Region:HRGN;
  TopLeft:TPoint;
  buffsize:Integer;
  buff:PRGNDATA;
  Rect:TRect;

begin

case MessageID of
  WM_PAINT:
        begin


        region := CreateRectRgn(0, 0, 0, 0);
        if (GetUpdateRgn(hw,region,False) <> ERROR) then
                begin
                TopLeft.x := 0;
                TopLeft.y := 0;
                if (not ClientToScreen(hw, TopLeft)) then exit;
                        buffsize := GetRegionData(region, 0, 0);
                        if (buffsize <> 0) then
                                begin
                                new(Buff);

                                if GetRegionData(region, buffsize, buff) <> 0 then
                                        for x:=0 to buff.rdh.nCount -1 do
                                          begin

                                        // THIS IS THE LINE I CAN'T FIGURE OUT
                                        // RECT *urect = (RECT *) (((BYTE *) buff) + sizeof(RGNDATAHEADER) + (x * sizeof(RECT)));


                                        //Don't Worry about the SendDeferredUpdateRect line
                                          
                                          end;

                                Dispose(Buff);
                                end;
                end;
      if Region <> 0 then
        DeleteObject(region);
      end;

  end;

end;

0
rbohac
Asked:
rbohac
  • 2
1 Solution
 
classmateCommented:
{
I think this part is included in windows.pas
type
  PRect = ^TRect;
}

var
  urect : PRect;

begin
.
.
  urect := PRect (integer(buff) + sizeof(RGNDATAHEADER) + x*sizeof(TRect) );
.
.
end;

regards
classmate
0
 
rbohacAuthor Commented:
cool. Looks like it worked. Thank you!
0
 
classmateCommented:
Any pointer type can be type-casted to integer, and type-casted back to any pointer type.
The integer type address value is useful when you need to calculate a memory address.

0
 
thegettaCommented:
Listening
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now