How do I properly map a `MagImageScalingCallback` using JNA?

I am using jna.jar, jna-3.2.5.jar and jna-3.3.0-platform.jar in my Java Project.

This is the Winapi function I want to replicate.

BOOL WINAPI MagImageScalingCallback(
  _In_  HWND           hwnd,
  _In_  void           *srcdata,
  _In_  MAGIMAGEHEADER srcheader,
  _Out_ void           *destdata,
  _In_  MAGIMAGEHEADER destheader,
  _In_  RECT           unclipped,
  _In_  RECT           clipped,
  _In_  HRGN           dirty
);

This is my Java code

public interface MagImageScalingCallback extends StdCallLibrary.StdCallCallback{
    public boolean MagImageScalingCallback(HWND hwnd,
            Pointer srcdata,
            MAGIMAGEHEADER.ByValue srcheader,
            Pointer destdata,
            MAGIMAGEHEADER.ByValue destheader,
            RectByValue source,
            RectByValue clipped,
            HRGN dirty);
}

When I get into this method of the callback, I get unexpected results:

    public boolean MagImageScalingCallback(HWND hwnd, Pointer srcdata,
            MAGIMAGEHEADER.ByValue srcheader, Pointer destdata,
            MAGIMAGEHEADER.ByValue destheader, RectByValue source, RectByValue clipped, HRGN dirty) {
        image.setRGB(0, 0, srcheader.width, srcheader.height, srcdata.getIntArray(0, srcheader.width * srcheader.height ), 0, srcheader.width);
        return true;
    }

This table explains What works and what doesn't work in 32 bit and 64 bit system when I change the data type of the variables.

+--------------+--------------+-------------+-------------+
| Parameter    | Data type    |   64 bit    |   32 bit    |
+--------------+--------------+-------------+-------------+
| source       | WinDef.RECT  |   Working   | Not Working |
| clipped      | WinDef.RECT  |   Working   | Not Working |
| source       | RectByValue  |   Working   |   Working   |
| source       | RectByValue  |   Working   |   Working   |
| srcdata      | Pointer      |   Working   | Not Working |
| destdata     | Pointer      |   Working   | Not Working |
+--------------+--------------+-------------+-------------+

Not working means a totally black image in the result

If I use the above code in a 64 bit system, I can capture the desktop(I can access the data from the Pointer variable). If I use the same code in 32 bit system, I am not getting any image. You can see my whole code

Why is the error in my code? How can I fix that?

For your Information. As you see in the screenSkip.java, Whenever MagSetWindowSource function is called. MagImageScalingCallback(in line 80) is called.

Problems in this section of code

If I run this code on a 64 bit system srcdata and destdata will hold the array of integer pixels of the Desktop(If I save this as image, it captures the desktop). But if I run the same code on 32 bit system these both variable array pixel value is always zero(If I save the image, it is always black)

64 bit system enter image description here

32 bit system enter image description here

@david-heffernan I am running this code on a 32-bit system. I know The Magnification API is not supported under WOW64;. Which means 32-bit magnification application works on a 32-bit system and 64-bit magnification application works on a 64-bit system. Please stop commenting that magnification API doesn't work on WOW64 and try to execute this code on a 32-bit system.

As for your request the below image shows the configuration of my System.

enter image description here


The callback is proper - there is no flaw in your code, besides you are using deprecated functions.

Consider using this:

try {
    Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    BufferedImage  capture = new Robot().createScreenCapture(screenRect);
    ImageIO.write(capture, "JPEG", new File("printed1.jpg"));
} catch (Exception e) {
    e.printStackTrace();
}