dll 创建
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//dll是个好东西,呵呵,下面简单的总结下dll的创建和调用。
//创建:
//dll.h
////////////////////////////////////////////
#ifndef dll_h_
#define dll_h_
#define MYFIRSTDLL extern "C" _declspec(dllexport)
MYFIRSTDLL void ShowText(void);
#endif
//dll.cpp ////////////////////////////////////////////
//#define MYFIRSTDLL extern "C" _declspec(dllexport);
#include
#include "dll.h"
void ShowMsg()
{
printf("this is a dll show!\n");
}
编译,在debug目录下产生dll.lib 和dll/lib。
调用:
显式调用和隐式调用
显式调用:只需要用到.dll
隐式调用:用到.dll .h .lib
显式调用:::
//testdll.cpp
//////////////////////
#include
#include
#include
HMODULE hdll=LoadLibrary("dll.dll");
typedef (*pShowText)();
pShowText ShowText=(pShowText)GetProcAddress(hdll,"ShowText");
int main()
{
ShowText();
printf("this is a execute show\n");
return 1;
}
隐式调用:::::
//testdll.cpp
//author:lyw
//time:2006.12.19
//////////////////////
#include
#include
#include
#include "dll.h"
#pragma comment(lib,"dll.lib")
int main()
{
ShowMsg();
printf("this is a execute show\n");
return 1;
}
//相应的.lib文件放到lib 中,.h文件包含在include中,需要注意的是.dll文件程序会在system32目录下,
//环境变量path定义的文件下和程序所在目录三个地方查找。
//创建:
//dll.h
////////////////////////////////////////////
#ifndef dll_h_
#define dll_h_
#define MYFIRSTDLL extern "C" _declspec(dllexport)
MYFIRSTDLL void ShowText(void);
#endif
//dll.cpp ////////////////////////////////////////////
//#define MYFIRSTDLL extern "C" _declspec(dllexport);
#include
#include "dll.h"
void ShowMsg()
{
printf("this is a dll show!\n");
}
编译,在debug目录下产生dll.lib 和dll/lib。
调用:
显式调用和隐式调用
显式调用:只需要用到.dll
隐式调用:用到.dll .h .lib
显式调用:::
//testdll.cpp
//////////////////////
#include
#include
#include
HMODULE hdll=LoadLibrary("dll.dll");
typedef (*pShowText)();
pShowText ShowText=(pShowText)GetProcAddress(hdll,"ShowText");
int main()
{
ShowText();
printf("this is a execute show\n");
return 1;
}
隐式调用:::::
//testdll.cpp
//author:lyw
//time:2006.12.19
//////////////////////
#include
#include
#include
#include "dll.h"
#pragma comment(lib,"dll.lib")
int main()
{
ShowMsg();
printf("this is a execute show\n");
return 1;
}
//相应的.lib文件放到lib 中,.h文件包含在include中,需要注意的是.dll文件程序会在system32目录下,
//环境变量path定义的文件下和程序所在目录三个地方查找。