Programm schmiert ab
-
Hi,
ich habe folgenden Code:
HRESULT CBitmapGDI::load (std::string FileName) { if (this->m_DIB) { delete [] this->m_DIB; this->m_DIB = NULL; } HANDLE FileHandle; BITMAPFILEHEADER DIBHeader; // File information of the (valid) bitmap DWORD BytesRead; // Number of bytes read, used to test if ((UINT)(FileHandle = CreateFile (FileName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0)) == 0xffffffff) { // Datei nicht gefunden, Funktion beenden! return E_FAIL; } ReadFile (FileHandle, &DIBHeader, sizeof (BITMAPFILEHEADER), &BytesRead, NULL); if (BytesRead != sizeof (BITMAPFILEHEADER) || DIBHeader.bfType != 0x4D42) { CloseHandle (FileHandle); return E_FAIL; } if (!(this->m_DIBbits = new UCHAR [DIBHeader.bfSize - sizeof (BITMAPFILEHEADER)])) { CloseHandle (FileHandle); return E_FAIL; } ReadFile (FileHandle, this->m_DIBbits, DIBHeader.bfSize, &BytesRead, NULL); if (BytesRead != DIBHeader.bfSize - sizeof (BITMAPFILEHEADER)) { CloseHandle (FileHandle); return E_FAIL; } CloseHandle (FileHandle); this->m_BitmapInfo = reinterpret_cast <BITMAPINFO*> (this->m_DIB); this->m_DIBbits = this->m_DIB + this->m_BitmapInfo->bmiHeader.biSize; // << Genau Hier schmiert er ab mit einer "Unhandled Exception"! if (this->m_BitmapInfo->bmiHeader.biBitCount <= 8) { this->m_DIBbits += (1 << this->m_BitmapInfo->bmiHeader.biBitCount) * sizeof (RGBQUAD); } this->m_width = this->m_BitmapInfo->bmiHeader.biWidth; this->m_height = this->m_BitmapInfo->bmiHeader.biHeight; if (this->m_BitmapInfo->bmiHeader.biHeight > 0) { this->m_BitmapInfo->bmiHeader.biHeight =- this->m_BitmapInfo->bmiHeader.biHeight; } return S_OK; }
Dies hier steht in der MessageBox die erscheint:
Unhandled exception at 0x0041436a in Win32API Wrapper.exe: 0xC0000005: Access violation reading location 0x00000000.
Weiß einer wieso das Programm abschmiert?
-
Achja das sind die Members:
private: int m_x; int m_y; int m_width; int m_height; UCHAR *m_DIB; BITMAPINFO *m_BitmapInfo; UCHAR *m_DIBbits; };
-
Du setzt doch oben this->m_DIB auf NULL und castest es dann nach this->m_BitmapInfo - eigentlich müssten dann doch beide NULL sein
Wass willst du damit bezwecken, oder blick ich es grad nur nicht