ä¸ãå建å¨æé¾æ¥åºé¡¹ç®ï¼
1ãæå¼Microsoft Visual Studio 2010ï¼éæ©File->New->Projectã
2ãå¨New Projectä¸éæ©Installed Templates->Visual C++->Win32ã
3ãéæ©Win32 Console Applicationï¼è®¾ç½®å称ï¼simpledllï¼è®¾ç½®è§£å³æ¹æ¡åï¼zdddllã
4ãåå»OKï¼å¨åºç°çWin32 Application WizardçOverview对è¯æ¡ä¸ç¹å»Nextã
5ãå¨Application Settingsä¸ï¼éæ©Application typeä¸çDLLã
6ãå¾éAdditional optionsä¸çEmpty projectã
7ãåå»Finishå建项ç®ã
åå¨æé¾æ¥åºæ·»å ç±»ï¼
1ãæ·»å æ°ç±»å¤´æ件ãå³é®åå»simpledll项ç®ï¼Add->New Itemï¼éæ©Header File(.h)ï¼è®¾ç½®å称为simpledllï¼åå»Addã
2ãæ·»å æ°ç±»æºæ件ãå³é®åå»simpledll项ç®ï¼Add->New Itemï¼éæ©C++ File(.cpp)ï¼è®¾ç½®å称为simpledllï¼åå»Addã
3ã为æ°ç±»æ·»å å
容ãå
容å¦ä¸ï¼
头æ件simpledll.hï¼
//------------------ simpledll.h ----------------
#pragma once;
//该å®å®æå¨dll项ç®å
é¨ä½¿ç¨__declspec(dllexport)导åº
//å¨dll项ç®å¤é¨ä½¿ç¨æ¶ï¼ç¨__declspec(dllimport)导å
¥
//å®DLL_IMPLEMENTå¨simpledll.cppä¸å®ä¹
#ifdef DLL_IMPLEMENT
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif
namespace zdd
{
//导åºç±»
class DLL_API SimpleDll
{
public:
SimpleDll();
~SimpleDll();
int add(int x, int y); //ç®åæ¹æ³
};
}
æºæ件simpledll.cpp:
//------------------ simpledll.cpp ----------------
//注ææ¤å¤çå®å®ä¹éè¦åå¨#include "simpledll.h"ä¹å
//以å®æå¨dll项ç®å
é¨ä½¿ç¨__declspec(dllexport)导åº
//å¨dll项ç®å¤é¨ä½¿ç¨æ¶ï¼ç¨__declspec(dllimport)导å
¥
#define DLL_IMPLEMENT
#include "simpledll.h"
namespace zdd
{
SimpleDll::SimpleDll()
{
}
SimpleDll::~SimpleDll()
{
}
int SimpleDll::add(int x, int y)
{
return x+y;
}
}
4ãå®æåç¹å»Build->Build Solutionï¼çæ解å³æ¹æ¡ãå¯å¨~zdddll\Debugä¸æ¥ççæçsimpledll.libåsimpledll.dll.æ件ã
äºãå建å¼ç¨å¨æé¾æ¥åºçåºç¨ç¨åºï¼
1ãéæ©File->New->Projectã
2ãå¨New Projectä¸éæ©Installed Templates->Visual C++->Win32ã
3ãéæ©Win32 Console Applicationï¼è®¾ç½®å称ï¼usesimpledllãéæ©Add to solutionã
4ãåå»OKï¼å¨åºç°çWin32 Application WizardçOverview对è¯æ¡ä¸ç¹å»Nextã
5ãå¨Application Settingsä¸ï¼éæ©Application typeä¸çConsole applicationã
6ãåæ¶Additional optionsä¸çPrecompiled headerï¼å¾éEmpty projectã
7ãåå»Finishå建项ç®ã
温馨提示:内容为网友见解,仅供参考