First, two aside remarks about your code, given the fact you are using MFC:
- You have defined your own class for manipulating files while MFC has CFile class.
- You are using std::vector<BYTE> while MFC has CByteArray class.
Besides, my post #20 is enough clear: the problem from the title of this thread is because of wrong using of GetLastError and not because of LoadImage function itself.
Then, it has not much sense reinventing the wheel and bittwiddlering in bitmap format structures.
One good approach is to extend CBitmap class by adding FromFile method as follows:
Code:struct CBitmapEx : public CBitmap { DWORD FromFile(LPCTSTR szFileName, BOOL bDIBSection = TRUE); };Another easier way is to use CImage ATL/MFC class instead of CBitmap.Code:DWORD CBitmapEx::FromFile(LPCTSTR szFileName, BOOL bDIBSection) { DWORD dwRet = NO_ERROR; if(NULL != GetSafeHandle()) DeleteObject(); UINT nFlags = LR_LOADFROMFILE; if(bDIBSection) nFlags |= LR_CREATEDIBSECTION; HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, szFileName, IMAGE_BITMAP, 0, 0, nFlags); if(NULL == hBitmap) dwRet = ::GetLastError(); else Attach(hBitmap); return dwRet; }




Reply With Quote