Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

StretchBlt fails with error 5 (access denied)

75 views
Skip to first unread message

Derek

unread,
Dec 19, 2008, 2:00:35 PM12/19/08
to
I have a simple console application program that captures a screenshot
of the display device and then saves the image to file as a bitmap.
The screenshot is generated successfully when run with my
(administrative) account, but when run under the local system account
it fails. Specifically, the StretchBlt( ) function fails and last
error is set to 5 (access denied).

The sequence of Windows API calls is as follows:

HDC sourceDC =
CreateDC( L"DISPLAY", // lpszDriver - driver name
NULL, // lpszDevice -
device name
NULL, // lpszOutput - not
used; should be NULL
NULL );

HDC memoryDC =
CreateCompatibleDC( sourceDC );

HBITMAP bitmap =
CreateCompatibleBitmap( sourceDC, //
hdc - handle to DC

horizontalResolution, // nWidth - width of bitmap, in pixels
verticalResolution );

SelectObject( memoryDC, // hdc - handle to DC
bitmap );

StretchBlt( memoryDC, //
hdcDest - handle to destination DC

0, // nXOriginDest - x-coord of
destination upper-left corner

0, // nYOriginDest - y-coord of
destination upper-left corner
horizontalResolution, //
nWidthDest - width of destination rectangle
verticalResolution, //
nHeightDest - height of destination rectangle
sourceDC, //
hdcSrc - handle to source DC

0, // nXOriginSrc - x-coord of
source upper-left corner

0, // nYOriginSrc - y-coord of
source upper-left corner
sourceHorizonalResolution, //
nWidthSrc - width of source rectangle
sourceVerticalResolution, //
nHeightSrc - height of source rectangle
SRCCOPY );

(Note: For clarity, I have omitted error checking code from the above
excerpt. I am evaluating and handling the return value of every
function.).

All operations up until the StretchBlt function succeed.

Anyone know of any reason why this would fail when run under the
system account? I have reproduced this on several systems including XP
Pro and Vista.

Thanks for your help.

0 new messages