// OsdLib.cpp : Defines the entry point for the DLL application.
//#include <windows.h>
#include <stdlib.h>         
#include <stdio.h>
#include <malloc.h>
#include <iostream.h>
#include "stdafx.h"void bmp8_reverse (BYTE *pRgb, int width, int height)
{
BYTE *pTemp = (BYTE *)malloc (width * height);
BYTE *pDst = pTemp;
BYTE *pSrc = pRgb + (width * height);
ULONG bytes_in_line = width;
if (pDst == 0)
return;
for (int i=0; i<height; i++)
{
pSrc -= bytes_in_line;
memcpy (pDst, pSrc, bytes_in_line);
pDst += bytes_in_line;
}
memcpy (pRgb, pTemp, width * height); 
free (pTemp);
}
--------------------Configuration: OsdLib - Win32 Debug--------------------
Compiling...
OsdLib.cpp
F:\Delphi Project\OSDDLL\OsdLib\OsdLib.cpp(15) : error C2065: 'malloc' : undeclared identifier
F:\Delphi Project\OSDDLL\OsdLib\OsdLib.cpp(28) : error C2065: 'free' : undeclared identifier
Error executing cl.exe.OsdLib.obj - 2 error(s), 0 warning(s)
我都加了
#include <stdlib.h>         
#include <stdio.h>
#include <malloc.h>
#include <iostream.h>为什么还老说malloc 和 free:
undeclared identifier?

解决方案 »

  1.   

    可能跟你编译器的宏设置有关,虽然你包含那个头文件但是实际上编译器没有包含malloc的定义。
    直接将malloc的声明写出来试试:
    在你的程序前加:void *malloc( size_t size );
      

  2.   

    请把头文件的顺序换一换:#include "stdafx.h"放在最顶上#include "stdafx.h"
    #include <windows.h>
    #include <stdlib.h>         
    #include <stdio.h>
    #include <malloc.h>
    #include <iostream.h>
      

  3.   

    查来查去,发现好像malloc不可以用在Dll上吧?
      

  4.   

    晕,照Jdzwq说的方法试了,可以通过编译了,没懂为什么那个“stdafx.h"一定要放在最顶上啊?偶是菜鸟,请Jdzwq解释一下
      

  5.   

    因为你的OsdLib.cpp 在Project->Setting->c/c++->Category->Procompile Headers中选Using compilier header file(stdafx.h)
    就是说:编译器第一个找stdafx.h头文件,然后处理stdafx.h后面的头文件,stdafx.h放在最后,前面的头文件都被忽略了,产生了未定义的错误。
    不过在Project->Setting->c/c++->Category->Procompile Headers选Not using precompelier header,那么stdafx.h放在那里都无所谓,编译可以通过!
      

  6.   

    哦,偶看了Project->Setting
    发现是C/C++ -》 Catetgory -》 General,这个地方我什么也没有改,就是新建DLL项目后就这样的多谢啦