本文主要是介绍编写简单DLL及CL编译链接,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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
这篇关于编写简单DLL及CL编译链接的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!