CDib::CObject debug error?

This is a discussion on CDib::CObject debug error? within the C++ Programming forums, part of the General Programming Boards category; I am a newbie learnning vc++6.0,and now I read one book about graph process with vc++6.0, first lesson told me ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    98

    CDib::CObject debug error?

    I am a newbie learnning vc++6.0,and now I read one book
    about graph process with vc++6.0,
    first lesson told me must design one class CDib from CObject,
    so that we can process bmp which colors>256,
    this is Dib.h from my book:
    //--------------------

    #ifndef __CDIB_H
    #define __CDIB_H

    class CDibublic CObject
    {
    public:
    RGBQUAD * m_pRGB;
    BYTE * m_pData;
    UINT m_numberOfColors;
    BOOL m_valid;
    BITMAPFILEHEADER bitmapFileHeader;
    BITMAPINFOHEADER * m_pBitmapInfoHeader;
    BITMAPINFO * m_pBitmapInfo;
    BYTE * pDib;
    DWORD size;

    public:
    CDib();
    ~CDib();
    char m_fileName[256];
    char *GetFileName();
    BOOL IsValid();
    DWORD GetSize();
    UINT GetWidth();
    UINT GetHeight();
    UINT GetNumberOfColors();
    RGBQUAD *GetRGB();
    BYTE *GetData();
    BITMAPINFO *GetInfo();
    WORD PaletteSize(LPBYTE lpDIB);
    WORD DIBNumColors(LPBYTE lpDIB);
    void SaveFile(const CString filename);

    public:
    void LoadFile(const char *dibFileName);
    };

    #endif
    //-------------------------

    this is Dib.cpp:
    //-------------------------

    #include "stdafx.h"
    #include "Dib.h"
    #include "windowsx.h"

    CDib::CDib()
    {
    size=0;
    }
    CDib::~CDib()
    {
    GlobalFreePtr(m_pBitmapInfo);
    }
    void CDib::LoadFile(const char * dibFileName)
    {
    strcpy(m_fileName,dibFileName);
    CFile dibFile(m_fileName,CFile::modeRead);
    dibFile.Read((void *)&bitmapFileHeader,sizeof(BITMAPFILEHEADER));
    if(bitmapFileHeader.bfType==0x4d42)
    {
    DWORD fileLength=dibFile.GetLength();
    size=fileLength-sizeof(BITMAPFILEHEADER);
    pDib=(BYTE*)GlobalAllocPtr(GMEM_MOVEABLE,size);
    dibFile.Read((void *)pDib,size);
    dibFile.Close();
    m_pBitmapInfo=(BITMAPINFO*)pDib;
    m_pBitmapInfoHeader=(BITMAPINFOHEADER*)pDib;
    m_pRGB=(RGBQUAD*)(pDib+m_pBitmapInfoHeader->biSize);
    int m_numberOfColors=GetNumberOfColors();
    if(m_pBitmapInfoHeader->biClrUsed==0)
    m_pBitmapInfoHeader->biClrUsed=m_numberOfColors;
    DWORD colorTableSize=m_numberOfColors* sizeof(RGBQUAD);
    m_pData=pDib+m_pBitmapInfoHeader->biSize+colorTableSize;
    if(m_pRGB==(RGBQUAD*)m_pData) //No Color table
    m_pRGB=NULL;
    m_pBitmapInfoHeader->biSizeImage=GetSize();
    m_valid=TRUE;
    }
    else
    {
    m_valid=FALSE;
    AfxMessageBox("This isn't a bitmap file!");
    }
    }
    BOOL CDib::IsValid()
    {
    return m_valid;
    }
    char * CDib::GetFileName()
    {
    return m_fileName;
    }
    UINT CDib::GetWidth()
    {
    return (UINT) m_pBitmapInfoHeader->biWidth;
    }
    UINT CDib::GetHeight()
    {
    return (UINT) m_pBitmapInfoHeader->biHeight;
    }
    DWORD CDib::GetSize()
    {
    if(m_pBitmapInfoHeader->biSizeImage!=0)
    return m_pBitmapInfoHeader->biSizeImage;
    else
    {
    DWORD height=(DWORD)GetHeight();
    DWORD width=(DWORD)GetWidth();
    return height * width;
    }
    }
    UINT CDib::GetNumberOfColors()
    {
    int numberOfColors;
    if((m_pBitmapInfoHeader->biClrUsed==0)&&
    (m_pBitmapInfoHeader->biBitCount<9))
    {
    switch(m_pBitmapInfoHeader->biBitCount)
    {
    case 1:
    numberOfColors=2;
    break;
    case 4:
    numberOfColors=16;
    break;
    case 8:
    numberOfColors=256;
    }
    }
    else
    numberOfColors=(int)m_pBitmapInfoHeader->biClrUsed;
    return numberOfColors;
    }
    BYTE *CDib::GetData()
    {
    return m_pData;
    }
    RGBQUAD* CDib::GetRGB()
    {
    return m_pRGB;
    }
    BITMAPINFO * CDib::GetInfo()
    {
    return m_pBitmapInfo;
    }
    WORD CDib::PaletteSize(LPBYTE lpDIB)
    {
    return (DIBNumColors(lpDIB)*sizeof(RGBTRIPLE));
    }
    WORD CDib:IBNumColors(LPBYTE lpDIB)
    {
    WORD wBitCount; //DIB bit count
    wBitCount=((LPBITMAPCOREHEADER)lpDIB)->bcBitCount;
    switch(wBitCount)
    {
    case 1:
    return 2;
    case 4:
    return 16;
    case 8:
    return 256;
    default:
    return 0;
    }
    }
    void CDib::SaveFile(const CString filename)
    {
    strcpy(m_fileName,filename);
    CFile dibFile(m_fileName,CFile::modeCreate|CFile::modeWr ite);
    dibFile.Write((void*)&bitmapFileHeader,sizeof(BITM APFILEHEADER));
    dibFile.Write((void*)pDib,size);
    dibFile.Close();
    }
    //----------------------------

    I have complie dib.h and dib.cpp into dll and lib file,
    then I begin use CDib class into my first example prog in book,
    DYNSPLIT work to display one source bmp and edited bmp in
    a split window,
    this is dynsplitview.h:


    // dynsplitView.h : interface of the CDynsplitView class
    //
    /////////////////////////////////////////////////////////////////////////////

    #if !defined(AFX_DYNSPLITVIEW_H__639DBA56_CE12_469D_AC F2_42F3256E01C0__INCLUDED_)
    #define AFX_DYNSPLITVIEW_H__639DBA56_CE12_469D_ACF2_42F325 6E01C0__INCLUDED_

    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000


    class CDynsplitView : public CView
    {
    protected: // create from serialization only
    CDynsplitView();
    DECLARE_DYNCREATE(CDynsplitView)

    // Attributes
    public:
    CDynsplitDoc* GetDocument();

    // Operations
    public:

    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CDynsplitView)
    public:
    virtual void OnDraw(CDC* pDC); // overridden to draw this view
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    protected:
    virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
    virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
    virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
    //}}AFX_VIRTUAL

    // Implementation
    public:
    CPalette * hPalette;
    CPalette CreateBitmapPalette(CDib *pBitmap);
    virtual ~CDynsplitView();
    #ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
    #endif

    protected:

    // Generated message map functions
    protected:
    //{{AFX_MSG(CDynsplitView)
    // NOTE - the ClassWizard will add and remove member functions here.
    // DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };

    #ifndef _DEBUG // debug version in dynsplitView.cpp
    inline CDynsplitDoc* CDynsplitView::GetDocument()
    { return (CDynsplitDoc*)m_pDocument; }
    #endif

    /////////////////////////////////////////////////////////////////////////////

    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.

    #endif // !defined(AFX_DYNSPLITVIEW_H__639DBA56_CE12_469D_AC F2_42F3256E01C0__INCLUDED_)
    //--------------------------------

    THIS IS DYNSPLITVIEW.CPP:

    // dynsplitView.cpp : implementation of the CDynsplitView class
    //

    #include "stdafx.h"
    #include "dib.h"
    #include "dynsplit.h"
    #include "dynsplitDoc.h"
    #include "dynsplitView.h"

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif

    /////////////////////////////////////////////////////////////////////////////
    // CDynsplitView

    IMPLEMENT_DYNCREATE(CDynsplitView, CView)

    BEGIN_MESSAGE_MAP(CDynsplitView, CView)
    //{{AFX_MSG_MAP(CDynsplitView)
    // NOTE - the ClassWizard will add and remove mapping macros here.
    // DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG_MAP
    // Standard printing commands
    ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
    END_MESSAGE_MAP()

    /////////////////////////////////////////////////////////////////////////////
    // CDynsplitView construction/destruction

    CDynsplitView::CDynsplitView()
    {
    // TODO: add construction code here

    }

    CDynsplitView::~CDynsplitView()
    {
    }

    BOOL CDynsplitView::PreCreateWindow(CREATESTRUCT& cs)
    {
    // TODO: Modify the Window class or styles here by modifying
    // the CREATESTRUCT cs

    return CView::PreCreateWindow(cs);
    }

    /////////////////////////////////////////////////////////////////////////////
    // CDynsplitView drawing

    void CDynsplitView::OnDraw(CDC* pDC)
    {
    CDynsplitDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
    int m_scale=1;
    BYTE * pBitmapData=CDib->GetData();
    LPBITMAPINFO pBitmapInfo=CDib->GetInfo();
    int bitmapHeight=CDib->GetHeight();
    int bitmapWidth=CDib->GetWidth();
    int scaledWidth=(int)(bitmapWidth * m_scale);
    int scaledHeight=(int)(bitmapHeight * m_scale);
    if(CDib->GetRGB())
    {
    CPalette * hPalette=CreateBitmapPalette(CDib);
    CPalette * hOldPalette=pDC->SelectPalette(hPalette,true);
    pDC->RealizePalette();
    ::StretchDIBits(pDC->GetSafeHdc(),0,0,scaledWidth,
    scaledHeight,
    0,0,bitmapWidth,bitmapHeight,pBitmapData,pBitmapIn fo,
    DIB_RGB_COLORS,SRCCOPY);
    pDC->SelectPalette(hOldPalette,true);
    :eleteObject(hPalette);
    }
    }


    /////////////////////////////////////////////////////////////////////////////
    // CDynsplitView printing

    BOOL CDynsplitView::OnPreparePrinting(CPrintInfo* pInfo)
    {
    // default preparation
    return DoPreparePrinting(pInfo);
    }

    void CDynsplitView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
    // TODO: add extra initialization before printing
    }

    void CDynsplitView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
    // TODO: add cleanup after printing
    }

    /////////////////////////////////////////////////////////////////////////////
    // CDynsplitView diagnostics

    #ifdef _DEBUG
    void CDynsplitView::AssertValid() const
    {
    CView::AssertValid();
    }

    void CDynsplitView:ump(CDumpContext& dc) const
    {
    CView:ump(dc);
    }

    CDynsplitDoc* CDynsplitView::GetDocument() // non-debug version is inline
    {
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDynsplitDoc)));
    return (CDynsplitDoc*)m_pDocument;
    }
    #endif //_DEBUG

    /////////////////////////////////////////////////////////////////////////////
    // CDynsplitView message handlers

    CPalette CDynsplitView::CreateBitmapPalette(CDib *pBitmap)
    {
    struct
    {
    WORD Version;
    WORD NumberOfEntries;
    PALETTEENTRY aEntries[256];
    }palette={0x300,256};
    LPRGBQUAD pRGBTable=pBitmap->GetRGB();
    UINT numberOfColors=pBitmap->GetNumberOfColors();
    for(UINT x=0;x<numberOfColors;++x)
    {
    palette.aEntries[x].peRed=pRGBTable[x].rgbRed;
    palette.aEntries[x].peGreen=pRGBTable[x].rgbGreen;
    palette.aEntries[x].peBlue=pRGBTable[x].rgbBlue;
    palette.aEntries[x].peFlags=0;
    }
    hPalette.CreatePalette((LPLOGPALETTE)&palette);
    return &hPalette;
    }

    THIS IS ERROR MESSAGE:

    Compiling...
    dynsplitView.cpp
    E:\dynsplit\dynsplitView.cpp(63) : error C2819: type 'CDib' does not have an overloaded member 'operator ->'
    e:\dynsplit\dib.h(4) : see declaration of 'CDib'
    E:\dynsplit\dynsplitView.cpp(63) : error C2227: left of '->GetData' must point to class/struct/union
    E:\dynsplit\dynsplitView.cpp(64) : error C2819: type 'CDib' does not have an overloaded member 'operator ->'
    e:\dynsplit\dib.h(4) : see declaration of 'CDib'
    E:\dynsplit\dynsplitView.cpp(64) : error C2227: left of '->GetInfo' must point to class/struct/union
    E:\dynsplit\dynsplitView.cpp(65) : error C2819: type 'CDib' does not have an overloaded member 'operator ->'
    e:\dynsplit\dib.h(4) : see declaration of 'CDib'
    E:\dynsplit\dynsplitView.cpp(65) : error C2227: left of '->GetHeight' must point to class/struct/union
    E:\dynsplit\dynsplitView.cpp(66) : error C2819: type 'CDib' does not have an overloaded member 'operator ->'
    e:\dynsplit\dib.h(4) : see declaration of 'CDib'
    E:\dynsplit\dynsplitView.cpp(66) : error C2227: left of '->GetWidth' must point to class/struct/union
    E:\dynsplit\dynsplitView.cpp(69) : error C2143: syntax error : missing ')' before '->'
    E:\dynsplit\dynsplitView.cpp(69) : error C2143: syntax error : missing ';' before '->'
    E:\dynsplit\dynsplitView.cpp(69) : error C2059: syntax error : ')'
    E:\dynsplit\dynsplitView.cpp(70) : error C2143: syntax error : missing ';' before '{'
    E:\dynsplit\dynsplitView.cpp(71) : error C2275: 'CDib' : illegal use of this type as an expression
    e:\dynsplit\dib.h(4) : see declaration of 'CDib'
    E:\dynsplit\dynsplitView.cpp(144) : error C2228: left of '.CreatePalette' must have class/struct/union type
    E:\dynsplit\dynsplitView.cpp(145) : error C2660: 'CPalette::CPalette' : function does not take 1 parameters
    Error executing cl.exe.

    PLEASE GIVE ME SOME GUIDE :
    How to correct this error:

    E:\dynsplit\dynsplitView.cpp(63) : error C2819: type 'CDib' does not have an overloaded member 'operator ->'
    e:\dynsplit\dib.h(4) : see declaration of 'CDib'

    THANKS!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    PLEASE GIVE ME SOME GUIDE :
    What good would it do? Seriously. We already have forum guides, which you didn't read, or if you did, which I highly doubt, you ignored them. So how about you read the Announcements, find out what's wrong with your post, correct it by editing it, and try again.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    98
    sorry,if I post error place or message,because I have wasted almost one month to find the answer,
    I donnt need guide, just give small help about this error:

    type 'CDib' does not have an overloaded member 'operator ->'

    this is source prog : BYTE * pBitmapData=CDib->GetData();

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    sorry,if I post error place or message,because I have wasted almost one month to find the answer,
    I donnt need guide, just give small help about this error:
    And you still haven't read the Announcements...

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    98
    yes,I have disobeied Announcements 11.
    but DONNT PLAY WITH A NEWBIE JUST COMMING TO YOUR FORUM!!!

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why on earth would anyone help you when you blatantly disregard the forum rules? Someone lock this thread.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Jul 2004
    Posts
    98
    Some warmhearted vc++ gurus can help me ?

  8. #8
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    I love the smilies in the code. That always makes me want to read it.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  9. #9
    Programmer in Training TWIXMIX's Avatar
    Join Date
    Feb 2004
    Posts
    57
    I don't know how to help you but I have one thing to tell you.
    Put your code in the code tags to make it alot easier to read.
    Learning C++
    Programmer in training

  10. #10
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    As much as I hate myself for doing it, I think I found the problem. Did you ever instantiate a CDib object?
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  11. #11
    Registered User
    Join Date
    Jul 2004
    Posts
    98
    @TWIXMIX :
    THANKS FOR YOUR HELPNESS! shake your hands.

    @pianorain :
    THANKS A LOT. Please forgive me putting so long words make you headache,haha..
    but I dont see "instantiate a CDib object" what's mean?
    How to instantiate CDib?
    Please give me a simplesample,
    see you.

  12. #12
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Code:
    CDib *objCDib;
    objCDib = new CDib();
    Take note of the code tags.

    I cannot give you a satisfactory explanation of what is wrong; I can tell you that you need a CDib object somewhere in your CDynsplitView code. And probably a few other things too, after glancing at the error messages.

    Seriously, you'd get a better response by editing your first post and putting in some code tags.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  13. #13
    Registered User
    Join Date
    Jul 2004
    Posts
    98
    @pianorain :

    Thanks,I will go back test it,
    because I am a newbie ,before post this thread I hesitated a long time ,
    I donn't know how to select sticking point (important parts),
    at last I make this error decision.

    @quzah :
    Sorry for my disrespect action.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 03:09 AM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  4. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21