编写简单DLL及CL编译链接

来源:互联网 发布:360文件恢复软件下载 编辑:程序博客网 时间:2024/05/16 01:56
NO.1 使用DEF文件:


//dllsingle.h
#i nclude <windows.h>
INT APIENTRY add(int a,int b);


//dllsingle.cpp
#i nclude "dllsingle.h"
BOOL APIENTRY Entry()
{
return true;
}
INT APIENTRY add(int a,int b)
{
    return a + b;
}


//dllsingle.def
LIBRARY dllsingle.dll
EXPORTS
add


//compile bat file
cl dllsingle.cpp dllsingle.def /link /out:dllsingle.dll /dll /Entry:Entry /OPT:NOWIN98 /machine:x86
del dllsingle.exp dllsingle.obj
pause


NO.2 不使用DEF文件


//dllsingle1.h
extern "C" _declspec(dllexport) int add(int a, int b);


//dllsingle.cpp
#i nclude "dllsingle1.h"
int Entry()
{
return 1;
}
int add(int a,int b)
{
    return a + b;
}


//compile
cl dll2.cpp /link /out:dll2.dll /dll /Entry:Entry /OPT:NOWIN98 /machine:x86
del dll2.exp dll2.obj
pause