????????????????????У?????????????????????Щ??????????????а??????????г????????DLL???????????????????????????????????????????????????е?????????????????á?Windows API?е????к???????????DLL?С???????3???????DLL??Kernel32.dll?????????????????楨??????????????????User32.dll???????????????????????????細(xì)????????????????????????????GDI32.dll?????????????????????????????????

???????????????????????

????1?????????

????2?????????

?????????????????????????????????

?????????????????????????????

int _stdcall add(int a??int b)
{
 return a+b;
}

int _stdcall subtract(int a??int b)
{
 return a-b;
}

????????DLL????????????????????????????????????涼?????????_declspec(dllexport)

_declspec(dllexport) int _stdcall add(int a??int b)
{
 return a+b;
}

_declspec(dllexport) int _stdcall subtract(int a??int b)
{
 return a-b;
}

???????????????鶨?????.def???е???

????LIBRARY DllName
????EXPORTS
????add
????subtract

????????????????????????????£??????ο?C++???????????????

???????????????????????????????lib????????dll???????????lib????????????

?????????????????????????????????????(?????????.LIB)??????t?????????£??????????????????????????????и?????Щ????????????????????ó????????????????????????????????(.EXE???)??

????????????????????????????????????????????DLL????????????DLL???????????????????????DLL??????????????????????????????????????????????????DLL?е??????????????????????????????У??????е???????????DLL??????DLL?е??????????

??????????????ɡ?

???????????????????????????????????????????????????Щ????????????????????????????????lib?????????????????????????? ??????->????->???????????????????????

???????????????DLL??????????????????????DDL???????????????????????????????????DLL?е???????????

????????????????????????????????????LoadLibrary

??????MSDN?У?

????HMODULE WINAPI LoadLibrary(
????__in  LPCTSTR lpFileName
????);

????Maps the specified executable module into the address space of the calling process.

????????????????????????????????鵽???y????????????巽?????£?

????MFC????

HINSTANCE hInst;
hInst=LoadLibrary("Dll3.dll");//??Dll3??????????????
typedef int (/*_stdcall*/ *addFunPro)(int a??int b);//???????????????????????????????????????????溯?????
addFunPro AddFun=(addFunPro)GetProcAddress(hInst??MAKEINTRESOURCE(1));//??????????????
if(!AddFun)
{
 MessageBox("??????????????");
 return;
}
CString str;
str.Format("5+3=%d"??AddFun(5??3));//???????????????м??????
MessageBox(str);
FreeLibrary(hInst);