SetPixelFormat "Access is denied"?

This is driving me nuts… I hope someone can help me out with this… btw: i’m a newbie to opengl.

Here’s my snippet…

DWORD lastError;

HWND hWnd = this->getRenderHWND();

HDC hDC = GetDC(hWnd);

PIXELFORMATDESCRIPTOR pfd;
ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
int iFormat = ChoosePixelFormat( hDC, &pfd );

BOOL sret = SetPixelFormat( hDC, iFormat, &pfd );

if( FALSE == sret ) {
lastError = GetLastError();
LPVOID lpMsgBuf;

FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
lastError,
0,
(LPTSTR) &lpMsgBuf,
0,
NULL
);

debug(“SetPixelFormat error %u - %s”, lastError,
(char*)lpMsgBuf);

LocalFree( lpMsgBuf );
}

The debug statement prints:
SetPixelFormat error 3221684230 - Access is denied

So I figure I have atleast one problem, that SetPixelFormat is returning false. The other problem could be my FormatMessage is incorrect, thus giving a bogus error code and message. In any case, any idea why SetPixelFormat is failing? btw: I know the original HWND is valid, i print it out and compared it to the value as found in Spy++ and I did check to make sure GetDC is returning non-null.

One more piece of info. The handle to the window onto which I would like to draw belongs to a different application. Is that a problem?

Thanks,
Paul

try with :
pfd.cDepthBits = 24;

and maybe :
pfd.cColorBits = 8;

(I don’t remenber if this one is per component or for all 4 channels)

I still get the same error. I’m stumped.

Originally posted by Kryptos:
One more piece of info. The handle to the window onto which I would like to draw belongs to a different application. Is that a problem?
Could be, you have to get your own window, or make sure that the other app does the rendering, i think that is why you get the “Access is denied” error and not “Could not set the pixelformat” error.

And BTW ZbuffeR it should be 32 not 8.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.