Jump to content
  • Advertisement
Sign in to follow this  
themean

ChoosePixelFormat with GetLastError 2

This topic is 2512 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I have an unusual problem

unsigned long errors = GetLastError();
int nPixelFormat;
// get the best available match of pixel format for the device context
nPixelFormat = ChoosePixelFormat(this->hdc, &pfd);
// make that the pixel format of the device context
//SetPixelFormat(hdc, iPixelFormat, &pfd);

errors = GetLastError();


before SetPixelFormat call errors == 0 alfter that it is 2
I dont have any file operation in my code
any proposals ?

Share this post


Link to post
Share on other sites
Advertisement
ChoosePixelFormat returns 0 if there is an error, 1 or higher otherwise, so you should be checking the return value from that. Double-check what you've initialized your pfd struct to, you may have something bad in there (like, e.g, forgetting to init the nSize member, or just memset-zero-ing it). You can also use DescribePixelFormat to inspect the pixel format you got back, which can be useful for checking that it's what you actually want.

Share this post


Link to post
Share on other sites
Thanks
ChoosePixelFormat return me possitive number (7) and all work good except GetLastError which return 2 (ERROR_FILE_NOT_FOUND ->The system cannot find the file specified) and I cant understand why

Share this post


Link to post
Share on other sites
You shouldn't be relying on GetLastError for error checking here. The documentation for ChoosePixelFormat is quite clear that it's error condition is a return value of 0, and for SetPixelFormat it's condition is a return of FALSE. They're the conditions to check first, and only if they indicate an error should you test GetLastError to find out what the error was. In your case it could be giving a file not found error for any one of a number of reasons. Maybe there's legacy code in the Microsoft opengl32.dll that checks for an MCD and that is setting the error? Maybe there was an error condition that could be benignly recovered from in some other behind-the-scenes system call? Who knows. Either way it's not important and it's not a reliable way of testing whether a call has succeeded or failed. You got a 7, your call succeeded, and what GetLastError may or may not tell you is completely irrelevant. Check the documented error condition for your function call first, and only if that indicates an error use GetLastError.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!