写了一个DLL的测试程序,导出类,但是老是通不过,报错DLL1.h里面内容:#ifdef DLL1_API
#else
#define DLL1_API extern "C" _declspec(dllimport)
#endifDLL1_API int _stdcall add(int a,int b);
DLL1_API int _stdcall subtract(int a,int b);class  DLL1_API Point
{
public:
    void output(int x,int y);
void test();
};
dll1.cpp里面内容:#define DLL1_API extern "C" _declspec(dllexport)
#include "Dll1.h"
#include <Windows.h>
#include <stdio.h>int _stdcall add(int a,int b)
{
return a+b;
}int _stdcall subtract(int a,int b)
{
return a-b;
}void Point::output(int x,int y)
{
HWND hwnd=GetForegroundWindow();
HDC hdc=GetDC(hwnd);
char buf[20];
memset(buf,0,20);
sprintf(buf,"x=%d,y=%d",x,y);
TextOut(hdc,0,0,buf,strlen(buf));
ReleaseDC(hwnd,hdc);
}void Point::test()
{
}
报错:--------------------Configuration: Dll1 - Win32 Debug--------------------
Compiling...
Dll1.cpp
e:\dll1\dll1.h(10) : warning C4518: '$S1 ' : storage-class or type specifier(s) unexpected here; ignored
e:\dll1\dll1.h(10) : warning C4502: 'linkage specification' requires use of keyword 'extern' and must precede all other specifiers
e:\dll1\dll1.h(10) : error C2501: 'Point' : missing storage-class or type specifiers
e:\dll1\dll1.h(10) : error C2239: unexpected token '{' following declaration of 'Point'
e:\dll1\dll1.cpp(18) : error C2653: 'Point' : is not a class or namespace name
e:\dll1\dll1.cpp(29) : error C2653: 'Point' : is not a class or namespace name
Error executing cl.exe.Dll1.dll - 4 error(s), 2 warning(s)
这是书上的一个例子,不明白为什么我通不过啊,请各位帮帮忙指导一下小弟啊!!!

解决方案 »

  1.   

    你这个类导出时 不应该声明为_stdcall 
      

  2.   


    谢谢了  但是声明为_stdcall的是两个函数,不是那个类把_stdcall删掉还是一样的报错
    把两个函数删了只留类还是一样报错:.h#ifdef DLL1_API
    #else
    #define DLL1_API extern "C" _declspec(dllimport)
    #endif
    class  DLL1_API Point
    {
    public:
        void  output(int x,int y);
    void test();
    };
    .CPP#define DLL1_API extern "C" _declspec(dllexport)
    #include "Dll1.h"
    #include <Windows.h>
    #include <stdio.h>void Point::output(int x,int y)
    {
    HWND hwnd=GetForegroundWindow();
    HDC hdc=GetDC(hwnd);
    char buf[20];
    memset(buf,0,20);
    sprintf(buf,"x=%d,y=%d",x,y);
    TextOut(hdc,0,0,buf,strlen(buf));
    ReleaseDC(hwnd,hdc);
    }void Point::test()
    {
    }还是报一样的错误
      

  3.   

    谢谢楼上的  果然去掉就可以了还想请教为什么会这样呢?
    这里为什么不能使用extern "C"??
      

  4.   

      1.有没有在“工程”--“设置”---“link"里面导入lib文件
      2.Dll程序重新编译一会,要记得更新复制的Dll跟LIB文件
      
      

  5.   

    谢谢楼上,我的程序是要生成DLL不是使用它
    去掉extern "C"就可以了 还想请教这里为什么不能使用extern "C"??
      

  6.   

    C语言中有类吗?类是C++的,那句话的意思是:支持C语言!!