Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

c++ to Delphi (Part of VNC code)

Posted on 2003-12-01
4
Medium Priority
?
545 Views
Last Modified: 2010-04-05
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
Comment
Question by:rbohac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
classmate earned 500 total points
ID: 9850973
{
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
 
LVL 6

Author Comment

by:rbohac
ID: 9851256
cool. Looks like it worked. Thank you!
0
 
LVL 2

Expert Comment

by:classmate
ID: 9851298
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
 

Expert Comment

by:thegetta
ID: 9852382
Listening
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question