This Question is Assumed Answered

1 "correct" answer available (4 pts) 2 "helpful" answers available (2 pts)
6 Replies Last post: Jan 21, 2010 9:45 PM by eilon  
eilon   12 posts since
Oct 29, 2009
Currently Being Moderated

Jan 14, 2010 10:14 PM

getting WinPack exception

Hi,

 

I am trying to capture a window image for steaming it over the network.

 

The code that does the capture looks like:

 

public BufferedImage paintWindow(final Wnd window)
{
final Rect r = window.getWindowRect();
final WindowDC origDC = WindowDC.getWindowDC(window);
final DDBitmap cap = new DDBitmap(r.getWidth(), r.getHeight());
final DC memDC = DC.createCompatibleDC(origDC);

final Bitmap oldBitmap = memDC.selectObject(cap);

if (Wnd.getForegroundWindow().equals(window))

{
DC.bitBlt(memDC, 0, 0, r.getWidth(), r.getHeight(), origDC, 0, 0, DC.RasterOperation.SRCCOPY);
}
else
{
final Function PaintWindowFunc = User32.getInstance().
getFunction("PrintWindow");
PaintWindowFunc.invoke(result, window, memDC, new UInt(0));
}

memDC.selectObject(oldBitmap);

final BufferedImage img = cap.toImage();
oldBitmap.deleteObject();
cap.deleteObject();
memDC.release();
origDC.release();
return img;
}

 

This method is called a few times a second. After running for about a minute I get the following exception:

 

com.jniwrapper.win32.LastErrorException: The operation completed successfully.
com.jniwrapper.win32.gdi.WindowDC.<init>(WindowDC.java:40)
com.jniwrapper.win32.gdi.DDBitmap.<init>(DDBitmap.java:41)
com.jniwrapper.win32.gdi.DC.selectObject(DC.java:151)
paintWindow(Unknown Source)

 

The message "operation completed successfully" does not indicate what went wrong..

I assume there is some internal corruption. I am using JNIWrapper 3.8.1

 

Please advise.

 

Vladimir Ikryanov TeamDev Ltd. 1,013 posts since
Apr 24, 2006
Currently Being Moderated
1. Jan 16, 2010 4:49 PM in response to: eilon
Re: getting WinPack exception

Hi Eilon,

Please try to use the following way to create DDBitmap instance:

    final DC screenDC = DC.createDC("DISPLAY", null, null, null);
    final DC compatibleDC = DC.createCompatibleDC(screenDC);
    Bitmap imageBitmap = new DDBitmap();
    Gdi32.getInstance().getFunction("CreateCompatibleBitmap").invoke(
            imageBitmap, screenDC, new Int(width), new Int(height));

    Bitmap oldBitmap = compatibleDC.selectObject(imageBitmap);

Regards,

Vladimir Ikryanov

Vladimir Ikryanov TeamDev Ltd. 1,013 posts since
Apr 24, 2006
Currently Being Moderated
3. Jan 18, 2010 12:09 PM in response to: eilon
Re: getting WinPack exception

Hi Eilon,


Please use the following method implementation:

    static final Function FUNCTION_CREATE_DC = Gdi32.getInstance().getFunction("CreateDCW");
 
    public static DC createDC(String driver, String device, String output, DevMode initData)
    {
        DC dc = new DC();
        FUNCTION_CREATE_DC.invoke(dc, new Parameter[]{
                new Pointer(driver == null ? null : new WideString(driver)),
                new Pointer(device == null ? null : new WideString(device)),
                new Pointer(output == null ? null : new WideString(output)),
                new Pointer(initData == null ? null : initData)
        });
        return dc;
    }
 

Regards,

Vladimir Ikryanov

Vladimir Ikryanov TeamDev Ltd. 1,013 posts since
Apr 24, 2006
Currently Being Moderated
5. Jan 19, 2010 1:01 PM in response to: eilon
Re: getting WinPack exception

Hi Eilon,


It looks like ScreenDC is ok only for a screen shot. I think the sample you provided is ok except the LastErrorException. Please make sure that the same algorithm works without issues with the native sample. Maybe the reason of this error in algorithm and it's possible that you get the same results with a native sample.


Regards,

Vladimir Ikryanov

More Like This

  • Retrieving data ...