JBloggs2079
Technical User
Hi there,
I'm trying to convert a piece of Delphi to C, and am not sure what the following code is doing, if anyone here could help me out that'd be great.
Declared at the top is
function GetBigPointer(lp : pointer;
Offset : Longint) : Pointer;
begin
\{$IFDEF WIN32\}
GetBigPointer := @PByteArray(lp)^ ;Offset];
\{$ELSE\}
Offset := Offset + TPtrRec(lp).Lo;
GetBigPointer := Ptr(TPtrRec(lp).Hi + TPtrRec(Offset).Hi *
SelectorInc,
TPtrRec(Offset).Lo);
\{$ENDIF\}
hPixelBuffer : THandle; \{Handle to the pixel buffer\}
lpPixelBuffer : pointer; \{pointer to the pixel buffer\}
Further down there is
hPixelBuffer := GlobalAlloc(GHND, BitmapSize);
lpPixelBuffer := GlobalLock(hPixelBuffer);
FillChar(lpPixelBuffer^, BitmapSize, #0);
for i := 0 to 255 do
for j := 0 to 255 do
Byte(GetBigPointer(lpPixelBuffer, i + (j * 256))^) := j;
--------------
Now I'm assuming this should convert as
HANDLE hPixelBuffer;
HANDLE* lpPixelBuffer;
lpPixelBuffer = &hPixelBuffer
That is that hPixelBuffer is of type HANDLE from the Win32 api, and lpPixelBuffer is a pointer that points to it.
The FillChars I have as
hPixelBuffer = (HANDLE)malloc(bitmapSize);
memset (hPixelBuffer, 0, sizeof (bitmapSize));
I however have no idea whats going on with that function.
Its passing a pointer to a HANDLE plus a number. Say we go into the
\{$IFDEF WIN32\}
part
GetBigPointer := @PByteArray(lp)^ ;Offset];
This seems to return a @PByteArray which takes the pointer as a parameter, and using [Offset] as an array index. But an index to what array ? Is an array being created here or what? Then whatever is being returned here is going into
Byte(... return value ...) = j
If someone could explain this syntax, I'd much appreciate it.
Thanks
I'm trying to convert a piece of Delphi to C, and am not sure what the following code is doing, if anyone here could help me out that'd be great.
Declared at the top is
function GetBigPointer(lp : pointer;
Offset : Longint) : Pointer;
begin
\{$IFDEF WIN32\}
GetBigPointer := @PByteArray(lp)^ ;Offset];
\{$ELSE\}
Offset := Offset + TPtrRec(lp).Lo;
GetBigPointer := Ptr(TPtrRec(lp).Hi + TPtrRec(Offset).Hi *
SelectorInc,
TPtrRec(Offset).Lo);
\{$ENDIF\}
hPixelBuffer : THandle; \{Handle to the pixel buffer\}
lpPixelBuffer : pointer; \{pointer to the pixel buffer\}
Further down there is
hPixelBuffer := GlobalAlloc(GHND, BitmapSize);
lpPixelBuffer := GlobalLock(hPixelBuffer);
FillChar(lpPixelBuffer^, BitmapSize, #0);
for i := 0 to 255 do
for j := 0 to 255 do
Byte(GetBigPointer(lpPixelBuffer, i + (j * 256))^) := j;
--------------
Now I'm assuming this should convert as
HANDLE hPixelBuffer;
HANDLE* lpPixelBuffer;
lpPixelBuffer = &hPixelBuffer
That is that hPixelBuffer is of type HANDLE from the Win32 api, and lpPixelBuffer is a pointer that points to it.
The FillChars I have as
hPixelBuffer = (HANDLE)malloc(bitmapSize);
memset (hPixelBuffer, 0, sizeof (bitmapSize));
I however have no idea whats going on with that function.
Its passing a pointer to a HANDLE plus a number. Say we go into the
\{$IFDEF WIN32\}
part
GetBigPointer := @PByteArray(lp)^ ;Offset];
This seems to return a @PByteArray which takes the pointer as a parameter, and using [Offset] as an array index. But an index to what array ? Is an array being created here or what? Then whatever is being returned here is going into
Byte(... return value ...) = j
If someone could explain this syntax, I'd much appreciate it.
Thanks