C++ 外部库错误c++;

C++ 外部库错误c++;,c++,dll,extern,C++,Dll,Extern,我在编译DLL文件项目时遇到一些问题。有两个文件CDLL.h和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(dll

我在编译DLL文件项目时遇到一些问题。有两个文件CDLL.h和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;
    }

}
#包括“Stdafx.h”
#包括“CDLL.h”
#包括
#包括
名称空间CDLL
{
void CDLL::生成查找表(int-cont)
{
浮动步长,步长_值;
对于(int i=0;i<256;i++)
半透明[i]=i;
如果(控制>0)
{
无符号int MinBin=contr;
无符号整数MaxBin=255-控制;
步骤=sqrt((双)控制)/控制;
阶跃_值=0.0;
对于(int i=0;iRGB+pRgb->RGB绿色+pRgb->RGB蓝色)/3;
int k=半透明[灰色]-灰色;
pRgb->rgred=min(pRgb->rgred+k,255);
pRgb->rgbGreen=min(pRgb->rgbGreen+k,255);
pRgb->rgbBlue=min(pRgb->rgbBlue+k,255);
}
SetBitmapBits(*phBitmap,wByteCount,pBits);
返回TRUE;
}
}
我不明白为什么会出现这样的错误:

  • 错误C2061:语法错误:标识符“HBITMAP”CDLL.h
  • 错误C2511:'bool CDLL::CDLL::Contrast(HBITMAP*,int)':重载 在“CDLL::CDLL”CDLL.cpp中找不到成员函数

  • #2不是关于头文件中方法的声明吗?如何修复此问题?

    HBITMAP类型是一个。在代码中,似乎忘记了包含适当的头。这可能就是问题所在。

    当然,我看不出它是否包含在stdafx中。如果是这样的话,我会删除答案。你是对的,但是缺少标题不是我提到的#1、#2、#5个错误的原因。有时这些错误是因为其他原因出现的。Fx错误#2可能是因为编译器无法理解对比度函数的定义,并试图通过说语句应该在之前结束来解释这一点。这至少可能是原因。包括windows.h,它改变了很多,编辑了第一篇文章。我打赌这是CDLL.h中方法声明参数中的某些内容,我不知道它们是否正确放置。我暂时还没有使用C++。@你的USE2904111需要在你的DLL的头中包含<代码> > <代码>。code>HBITMAP在那里未定义,因此您的方法签名无效。之后,如果
    stdafx.h
    中没有定义
    #define
    您的
    min
    函数(我正在GCC中检查您的代码,所以我现在没有可用的标题)。