Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6985051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:37:47+00:00 2026-05-27T18:37:47+00:00

Background: I am using OpenCV2 library in my MFC application and SetDIBitsToDevice to display

  • 0

Background: I am using OpenCV2 library in my MFC application and SetDIBitsToDevice to display each image. My problem is that following code works with 90% of image files but does not work with certain rotated images for the reason I don’t know. Whole description of the issue is here

So I need to find out why the function is returning 0 error code for the images and what error I am getting from the function.

According to MSDN

If zero scan lines are set (such as when dwHeight is 0) or the
function fails, the function returns zero.

So if the function returns zero, how can I find details of the error?

UPDATE: I tried to use GetLastError() as following. But actually message was “Operation completed successfully” that is not true, of course. I would appreciate any hint or advice to attack this issue.

BITMAPINFO* bmi = (BITMAPINFO* )buffer; 
FillBitmapInfo(bmi,width,height,Bpp(pDoc->m_cvImage),0);
int result = SetDIBitsToDevice(pDC->GetSafeHdc(), 100, 100, width,
    height, 0, 0, 0, height, pDoc->m_cvImage.data, bmi,
    DIB_RGB_COLORS);
if(result==0) {
    DWORD error = GetLastError();
    LPVOID lpMsgBuf;
    FormatMessage( 
        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_SYSTEM | 
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        error,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
        (LPTSTR) &lpMsgBuf,
        0,
        NULL 
    );
    CString text;
    // Process any inserts in lpMsgBuf.
    text= (LPCTSTR)lpMsgBuf;
    // Free the buffer.
    LocalFree( lpMsgBuf );      
    int nResult = AfxMessageBox(text, MB_OK);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:37:48+00:00Added an answer on May 27, 2026 at 6:37 pm

    Most GDI functions do not use GetLastError() (some do, such as BitBlt()), and GDI does not define its own error codes other than 0 and GDI_ERROR. If a failure occurs, there is usually no way to determine what the actual error is. you just have to review your code with a fine tooth comb looking for logic mistakes.

    Since you are having issues with rotated images, I would start by looking at them first. They probably do not have the same dimensions that you are expecting, so they do not match the parameters you are passing to SetDIBitsToDevice().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background Using R to predict the next values in a series. Problem The following
I'm doing background subtraction using opencv. The problem is the foreground object is not
I have given a table background image using css background-image property. The cells are
I am attempting to overlay images on top of a background image using the
I am using following functions in my App delegate - (void)applicationWillResignActive:(UIApplication *)application { NSLog(@applicationWillResignActive);
i have 3 navigation controller and i want to change each background using different
i want to change navigation bar background using my own image, but i really
Is there a way to create a background using CSS without the image? with
Related to How do I give text or an image a transparent background using
How to get the following red boxes as background using only css and no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.