dll 导出类

来源:百度知道 编辑:UC知道 时间:2024/07/02 04:58:47
头文件为:
#ifdef DLL1_API
#else
#define DLL1_API extern "C" _declspec(dllimport)
#endif

DLL1_API int add(int a,int b);

class DLL1_API point
{
public:
void output(int x,int y);
};
源文件为:
#define DLL1_API extern "C" _declspec(dllexport)
#include "dff.h"
#include <stdio.h>
#include <Windows.h>

int add(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);
}
————————————————————————
执行结果是:
--------------------Configuration: dff - Win32 Debug--------------------
Compiling...
dff.cpp
d:\game\dff\dff.h(11) : warning C4518: '$S1 ' : storage-clas

不对哈,小弟。

不是这么用的哈,呵呵。
最好不要把extern "C"编入到宏里边去,这样你不好处理extern "C"的括号。

呃 还真能这么用....|||

class __declspec(dllexport) XXX {};

这里显然不能用extern "C" class是C++的