Irrsinnige Fehler



  • Guten Tag,
    nachdem ich mich die halbe Nacht verzweifelt mit dem Problem beschäftigt habe, aber keine Lösung fand, frage ich euch.

    Mein Quellcode gibt Fehler aus, die einfach nicht verständlich sind, weil der Text der als Fehler angeprangert wird nicht exestiert.

    Die Fehler 😃 habe ich als Kommentar hinter die funktionen gesetzt.

    BITMAPINFO CreateBitmapInfoStruct(HBITMAP hBmp)
    {
        BITMAP bmp;
        PBITMAPINFO pbmi;
        WORD    cClrBits;
        // Retrieve the bitmap color format, width, and height.
        if (!GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp))
            return NULL; //  :D HIER FEHLER NUMMER EINS: 
    // conversion from `int' to non-scalar type `BITMAPINFO' requested|
    
        // Convert the color format to a count of bits.
        cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);
        if (cClrBits == 1)
            cClrBits = 1;
        else if (cClrBits <= 4)
            cClrBits = 4;
        else if (cClrBits <= 8)
            cClrBits = 8;
        else if (cClrBits <= 16)
            cClrBits = 16;
        else if (cClrBits <= 24)
            cClrBits = 24;
        else cClrBits = 32;
    
        // Allocate memory for the BITMAPINFO structure. (This structure
        // contains a BITMAPINFOHEADER structure and an array of RGBQUAD
        // data structures.)
    
        if (cClrBits != 24)
            pbmi = (PBITMAPINFO) LocalAlloc(LPTR,
            sizeof(BITMAPINFOHEADER) +
            sizeof(RGBQUAD) * (1<< cClrBits));
    
        // There is no RGBQUAD array for the 24-bit-per-pixel format.
    
        else
            pbmi = (PBITMAPINFO) LocalAlloc(LPTR,
            sizeof(BITMAPINFOHEADER));
    
        // Initialize the fields in the BITMAPINFO structure.
    
        pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
        pbmi->bmiHeader.biWidth = bmp.bmWidth;
        pbmi->bmiHeader.biHeight = bmp.bmHeight;
        pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
        pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;
        if (cClrBits < 24)
            pbmi->bmiHeader.biClrUsed = (1<<cClrBits);
    
        // If the bitmap is not compressed, set the BI_RGB flag.
        pbmi->bmiHeader.biCompression = BI_RGB;
    
        // Compute the number of bytes in the array of color
        // indices and store the result in biSizeImage.
        // For Windows NT, the width must be DWORD aligned unless
        // the bitmap is RLE compressed. This example shows this.
        // For Windows 95/98/Me, the width must be WORD aligned unless the
        // bitmap is RLE compressed.
        pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * cClrBits +31) & ~31) /8
            * pbmi->bmiHeader.biHeight;
        // Set biClrImportant to 0, indicating that all of the
        // device colors are important.
        pbmi->bmiHeader.biClrImportant = 0;
        return pbmi; // :D HIER FEHLER NUMMER ZWEI:
    // conversion from `tagBITMAPINFO*' to non-scalar type `BITMAPINFO' requested| 
    }
    

    Zudem hat der Funktionsaufruf in main ein problem:

    PBITMAPINFO pBitmapInfo = CreateBitmapInfoStruct(hBit);
    //  cannot convert `BITMAPINFO' to `tagBITMAPINFO*' in initialization|
    

    Helft mir bitte!!! 😞



  • Alle Fehler haben damit zu tun, dass du andere Typen zurückgibst als sie vom Compiler laut Deklaration erwartet werden. Du musst nur den richtigen Rückgabetyp in der Funktionsdeklaration angeben oder entsprechend casten.



  • BITMAPINFO* CreateBitmapInfoStruct(HBITMAP hBmp)
    {
        BITMAP bmp;
        static BITMAPINFO *pbmi;
        WORD    cClrBits;
        // Retrieve the bitmap color format, width, and height.
        if (!GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp))
            return (BITMAPINFO*)NULL; //  :D HIER FEHLER NUMMER EINS:
    // conversion from `int' to non-scalar type `BITMAPINFO' requested|
    
        // Convert the color format to a count of bits.
        cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);
        if (cClrBits == 1)
            cClrBits = 1;
        else if (cClrBits <= 4)
            cClrBits = 4;
        else if (cClrBits <= 8)
            cClrBits = 8;
        else if (cClrBits <= 16)
            cClrBits = 16;
        else if (cClrBits <= 24)
            cClrBits = 24;
        else cClrBits = 32;
    
        // Allocate memory for the BITMAPINFO structure. (This structure
        // contains a BITMAPINFOHEADER structure and an array of RGBQUAD
        // data structures.)
    
        if (cClrBits != 24)
            pbmi = (PBITMAPINFO) LocalAlloc(LPTR,
            sizeof(BITMAPINFOHEADER) +
            sizeof(RGBQUAD) * (1<< cClrBits));
    
        // There is no RGBQUAD array for the 24-bit-per-pixel format.
    
        else
            pbmi = (PBITMAPINFO) LocalAlloc(LPTR,
            sizeof(BITMAPINFOHEADER));
    
        // Initialize the fields in the BITMAPINFO structure.
    
        pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
        pbmi->bmiHeader.biWidth = bmp.bmWidth;
        pbmi->bmiHeader.biHeight = bmp.bmHeight;
        pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
        pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;
        if (cClrBits < 24)
            pbmi->bmiHeader.biClrUsed = (1<<cClrBits);
    
        // If the bitmap is not compressed, set the BI_RGB flag.
        pbmi->bmiHeader.biCompression = BI_RGB;
    
        // Compute the number of bytes in the array of color
        // indices and store the result in biSizeImage.
        // For Windows NT, the width must be DWORD aligned unless
        // the bitmap is RLE compressed. This example shows this.
        // For Windows 95/98/Me, the width must be WORD aligned unless the
        // bitmap is RLE compressed.
        pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * cClrBits +31) & ~31) /8
            * pbmi->bmiHeader.biHeight;
        // Set biClrImportant to 0, indicating that all of the
        // device colors are important.
        pbmi->bmiHeader.biClrImportant = 0;
        return pbmi; // :D HIER FEHLER NUMMER ZWEI:
    // conversion from `tagBITMAPINFO*' to non-scalar type `BITMAPINFO' requested|
    }
    


  • mach den irsinnigen cast bitte raus CStern wir sind hier nicht beim völlig bekloppten c++ sondern bei C!



  • Sartin Zeuchtel schrieb:

    mach den irsinnigen cast bitte raus CStern wir sind hier nicht beim völlig bekloppten c++ sondern bei C!

    Wir sind hier genauer: Bei WINAPI.

    Und was konkret gefällt Dir an diesem:

    BITMAPINFO *pbmi;

    nicht?

    Über das hier:

    BITMAPINFO* CreateBitmapInfoStruct(HBITMAP hBmp)

    ließe ich mit mir diskutieren. Würde ich auch nicht so machen ...

    BOOL CreateBitmapInfoStruct(HBITMAP hBmp, PBITMAPINFO pbmp) ...
    vielleicht.



  • Genau! Denn hiervon ist die Rede!

    return (BITMAPINFO*)NULL;
    

    Ein einfaches NULL ist hier vollkommen ausreichend!



  • Sartin Zeuchtel schrieb:

    Genau! Denn hiervon ist die Rede!

    return (BITMAPINFO*)NULL;
    

    Ein einfaches NULL ist hier vollkommen ausreichend!

    Der Meinung bin ich auch. Am besten gar kein Pointer zurückgeben 😉



  • In C würde ich vermutlich BOOL CreateBitmapInfoStruct(HBITMAP hBmp, PBITMAPINFO pbmp) machen.
    In C++ würde ich BITMAPINFO CreateBitmapInfoStruct(HBITMAP hBmp) oder void CreateBitmapInfoStruct(HBITMAP hBmp, BITMAPINFO& bmi) machen.


Anmelden zum Antworten