Question

I got some problem with compiling DLL file project. There are 2 files CDLL.h and CDLL.cpp:

CDLL.h:

#pragma once

namespace CDLL {

    class CDLL
    {

        static unsigned char TransLut[256];

    public:
        __declspec(dllexport) void build_lookup_table ( int contr);
        __declspec(dllexport) bool Contrast(HBITMAP * phBitmap, int iCount);
    };
}

CDLL.cpp:

#include "Stdafx.h"
#include "CDLL.h"
#include <math.h>
#include <windows.h>

namespace CDLL
{
    void CDLL::build_lookup_table(int contr)
    {
        float step, step_value;

        for (int i=0; i < 256; i++)
            TransLut[i] = i;

        if (contr > 0)
        {
            unsigned int MinBin = contr;
            unsigned int MaxBin = 255 - contr;

            step = sqrt((double)contr)/contr;
            step_value = 0.0;

            for (int i = 0; i < MinBin; i++)
            {
                TransLut[i] = (unsigned char)step_value;
                step_value += step;
            }

            step = 256.0f / (float)(MaxBin-MinBin);

            for (int i = MinBin; i <= MaxBin; i++)
            {
                if (step_value > 255.0f)
                {
                    step_value = 255.0f;
                    step = 0.0f;
                }

                TransLut[i] = (unsigned char)step_value;
                step_value += step;
            }

            for (int i = MaxBin + 1; i < 256; i++)
                TransLut[i] = 255;

        }
        else if (contr < 0)
        {
                step = (256.0+(float)(contr*2))/256.0;
                step_value = (float)contr * -1.0;

                for (int i = 0;i < 256; i++)
                {
                    TransLut[i] = (unsigned char)step_value;
                    step_value += step;
                }
        }
    }

    bool CDLL::Contrast(HBITMAP * phBitmap, int iCount) 
    {
        BITMAP bm;
        BYTE * pBits;
        RGBQUAD * pRgb;
        WORD wByteCount;
        int i, iPixels, gray;

        build_lookup_table(iCount);

        // Take BITMAP structure from HBITMAP

        GetObject(*phBitmap, sizeof(BITMAP), &bm);

        // Calculate bytes to read

        wByteCount = bm.bmHeight * (2 * ((bm.bmWidth * bm.bmBitsPixel + 15) / 16));

        // Alocate momory for bits od pixels and get pointers

        pBits = (BYTE *) malloc(wByteCount);
        GetBitmapBits(*phBitmap, wByteCount, pBits);

        // Convert pointer to byte to pointer to RGBQUAD

        pRgb = (RGBQUAD *) pBits;

        // Operate on pixel's colors

        iPixels = wByteCount / (bm.bmBitsPixel / 8);

        for(int i = 0; i < iPixels; i++, pRgb++)
        {
            gray = (pRgb->rgbRed + pRgb->rgbGreen + pRgb->rgbBlue) / 3;
            int k = TransLut[gray]-gray;

            pRgb->rgbRed   = min(pRgb->rgbRed   + k, 255);
            pRgb->rgbGreen = min(pRgb->rgbGreen + k, 255);
            pRgb->rgbBlue  = min(pRgb->rgbBlue  + k, 255);
        }

        SetBitmapBits(*phBitmap, wByteCount, pBits);

        return TRUE;
    }

}

The thing I do not get why I get such an errors like:

  1. error C2061: syntax error : identifier 'HBITMAP' CDLL.h
  2. error C2511: 'bool CDLL::CDLL::Contrast(HBITMAP *,int)' : overloaded member function not found in 'CDLL::CDLL' CDLL.cpp

Isn't #2 about the declaration of method in header file? How should I fix this one?

Was it helpful?

Solution

The HBITMAP type is a windows specific type. In your code it seems like you have forgotten to include the appropriate header. This may be the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top