{"id":47143,"date":"2025-07-30T06:31:48","date_gmt":"2025-07-29T22:31:48","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/47143.html"},"modified":"2025-07-30T06:31:48","modified_gmt":"2025-07-29T22:31:48","slug":"windows-%e5%8a%a8%e6%80%81%e9%93%be%e6%8e%a5%e5%ba%93dynamic-link-library%ef%bc%88-dll%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/47143.html","title":{"rendered":"Windows---\u52a8\u6001\u94fe\u63a5\u5e93Dynamic Link Library\uff08.dll\uff09"},"content":{"rendered":"<h3>DLL\u7684\u201c\u5e55\u540e\u82f1\u96c4\u201d\u89d2\u8272<\/h3>\n<p>\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u7684\u751f\u6001\u4e2d&#xff0c;\u6709\u4e00\u7c7b\u6587\u4ef6\u59cb\u7ec8\u626e\u6f14\u7740\u201c\u5e55\u540e\u82f1\u96c4\u201d\u7684\u89d2\u8272\u2014\u2014\u5b83\u4eec\u4e0d\u50cf.exe\u6587\u4ef6\u90a3\u6837\u76f4\u63a5\u5448\u73b0\u4e3a\u7528\u6237\u53ef\u89c1\u7684\u7a0b\u5e8f\u7a97\u53e3&#xff0c;\u5374\u652f\u6491\u7740\u51e0\u4e4e\u6240\u6709\u5e94\u7528\u7a0b\u5e8f\u7684\u8fd0\u884c&#xff1b;\u5b83\u4eec\u4e0d\u5355\u72ec\u6267\u884c&#xff0c;\u5374\u627f\u8f7d\u7740\u7cfb\u7edf\u4e0e\u8f6f\u4ef6\u7684\u6838\u5fc3\u529f\u80fd\u3002\u8fd9\u7c7b\u6587\u4ef6\u5c31\u662f\u52a8\u6001\u94fe\u63a5\u5e93&#xff08;Dynamic Link Library&#xff0c;\u7b80\u79f0DLL&#xff09;\u3002<\/p>\n<p>\u4ece\u7528\u6237\u53cc\u51fb\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u56fe\u6807\u5f00\u59cb&#xff0c;\u5230\u7a97\u53e3\u6e32\u67d3\u3001\u9f20\u6807\u70b9\u51fb\u54cd\u5e94\u3001\u6587\u4ef6\u4fdd\u5b58\u7b49\u64cd\u4f5c&#xff0c;\u80cc\u540e\u90fd\u79bb\u4e0d\u5f00DLL\u7684\u53c2\u4e0e&#xff1a;kernel32.dll\u7ba1\u7406\u7740\u8fdb\u7a0b\u4e0e\u5185\u5b58&#xff0c;user32.dll\u63a7\u5236\u7740\u7a97\u53e3\u4e0e\u8f93\u5165&#xff0c;gdi32.dll\u8d1f\u8d23\u56fe\u5f62\u7ed8\u5236\u2026\u2026\u5373\u4fbf\u662f\u7b2c\u4e09\u65b9\u8f6f\u4ef6&#xff0c;\u4e5f\u4f9d\u8d56\u81ea\u5b9a\u4e49DLL\u5b9e\u73b0\u6a21\u5757\u5316\u5f00\u53d1\u3002\u53ef\u4ee5\u8bf4&#xff0c;\u6ca1\u6709DLL&#xff0c;\u73b0\u4ee3Windows\u5e94\u7528\u7684\u9ad8\u6548\u8fd0\u884c\u4e0e\u7075\u6d3b\u6269\u5c55\u5c06\u65e0\u4ece\u8c08\u8d77\u3002<\/p>\n<h3>\u4e00\u3001DLL\u7684\u672c\u8d28&#xff1a;\u5b9a\u4e49\u4e0e\u6838\u5fc3\u7279\u5f81<\/h3>\n<h4>1.1 \u4ec0\u4e48\u662fDLL&#xff1f;<\/h4>\n<p>\u52a8\u6001\u94fe\u63a5\u5e93&#xff08;DLL&#xff09;\u662f\u4e00\u79cd\u5305\u542b\u53ef\u6267\u884c\u4ee3\u7801\u3001\u6570\u636e\u6216\u8d44\u6e90\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6&#xff0c;\u5176\u6838\u5fc3\u4f5c\u7528\u662f\u4e3a\u591a\u4e2a\u5e94\u7528\u7a0b\u5e8f&#xff08;\u6216\u5176\u4ed6DLL&#xff09;\u63d0\u4f9b\u5171\u4eab\u7684\u51fd\u6570\u3001\u53d8\u91cf\u6216\u8d44\u6e90\u3002\u4e0e.exe&#xff08;\u53ef\u6267\u884c\u6587\u4ef6&#xff09;\u4e0d\u540c&#xff0c;DLL\u65e0\u6cd5\u5355\u72ec\u8fd0\u884c&#xff0c;\u5fc5\u987b\u88ab\u5176\u4ed6\u7a0b\u5e8f&#xff08;\u8fdb\u7a0b&#xff09;\u52a0\u8f7d\u540e\u624d\u80fd\u53d1\u6325\u4f5c\u7528\u3002<\/p>\n<p>\u4ece\u6280\u672f\u672c\u8d28\u770b&#xff0c;DLL\u662fWindows\u201c\u52a8\u6001\u94fe\u63a5\u201d\u673a\u5236\u7684\u8f7d\u4f53\u3002\u201c\u52a8\u6001\u94fe\u63a5\u201d\u6307\u7684\u662f&#xff1a;\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u624d\u4f1a\u52a0\u8f7d\u6240\u9700\u7684DLL&#xff0c;\u5e76\u5c06\u5176\u4e2d\u7684\u51fd\u6570\u5730\u5740\u94fe\u63a5\u5230\u81ea\u8eab\u7684\u4ee3\u7801\u4e2d&#xff0c;\u800c\u975e\u5728\u7f16\u8bd1\u65f6\u5c31\u5c06DLL\u7684\u4ee3\u7801\u590d\u5236\u5230\u7a0b\u5e8f\u5185\u90e8&#xff08;\u9759\u6001\u94fe\u63a5&#xff09;\u3002\u8fd9\u79cd\u673a\u5236\u4ece\u6839\u672c\u4e0a\u6539\u53d8\u4e86\u8f6f\u4ef6\u7684\u6a21\u5757\u5316\u4e0e\u8d44\u6e90\u5171\u4eab\u65b9\u5f0f\u3002<\/p>\n<h4>1.2 DLL\u4e0eEXE\u7684\u6838\u5fc3\u533a\u522b<\/h4>\n<p>\u5c3d\u7ba1DLL\u4e0eEXE\u540c\u5c5eWindows\u7684PE&#xff08;Portable Executable&#xff0c;\u53ef\u79fb\u690d\u53ef\u6267\u884c\u6587\u4ef6&#xff09;\u683c\u5f0f&#xff0c;\u4f46\u4e24\u8005\u5b58\u5728\u672c\u8d28\u5dee\u5f02&#xff1a;<\/p>\n<table>\n<tr>\u7279\u5f81DLLEXE<\/tr>\n<tbody>\n<tr>\n<td>\u6267\u884c\u65b9\u5f0f<\/td>\n<td>\u65e0\u6cd5\u5355\u72ec\u8fd0\u884c&#xff0c;\u9700\u88ab\u5176\u4ed6\u7a0b\u5e8f\u52a0\u8f7d<\/td>\n<td>\u53ef\u72ec\u7acb\u542f\u52a8&#xff0c;\u4f5c\u4e3a\u8fdb\u7a0b\u5165\u53e3<\/td>\n<\/tr>\n<tr>\n<td>\u5165\u53e3\u51fd\u6570<\/td>\n<td>DllMain&#xff08;\u53ef\u9009&#xff0c;\u7528\u4e8e\u521d\u59cb\u5316\/\u6e05\u7406&#xff09;<\/td>\n<td>WinMain\/main&#xff08;\u5fc5\u987b&#xff0c;\u8fdb\u7a0b\u542f\u52a8\u70b9&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5185\u5b58\u52a0\u8f7d<\/td>\n<td>\u88ab\u6620\u5c04\u5230\u8c03\u7528\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4<\/td>\n<td>\u81ea\u8eab\u4f5c\u4e3a\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u8d77\u70b9<\/td>\n<\/tr>\n<tr>\n<td>\u4e3b\u8981\u7528\u9014<\/td>\n<td>\u63d0\u4f9b\u5171\u4eab\u51fd\u6570\u3001\u8d44\u6e90&#xff0c;\u652f\u6301\u6a21\u5757\u5316<\/td>\n<td>\u5b9e\u73b0\u72ec\u7acb\u529f\u80fd&#xff0c;\u4f5c\u4e3a\u7528\u6237\u4ea4\u4e92\u7684\u76f4\u63a5\u8f7d\u4f53<\/td>\n<\/tr>\n<tr>\n<td>\u94fe\u63a5\u65b9\u5f0f<\/td>\n<td>\u88ab\u5176\u4ed6\u6a21\u5757&#xff08;EXE\/DLL&#xff09;\u52a8\u6001\u94fe\u63a5<\/td>\n<td>\u53ef\u94fe\u63a5\u5176\u4ed6DLL&#xff0c;\u4f46\u81ea\u8eab\u662f\u94fe\u63a5\u7684\u7ec8\u70b9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7b80\u8a00\u4e4b&#xff0c;EXE\u662f\u201c\u4e3b\u89d2\u201d&#xff0c;\u8d1f\u8d23\u542f\u52a8\u8fdb\u7a0b\u5e76\u4e3b\u5bfc\u6267\u884c\u6d41\u7a0b&#xff1b;DLL\u662f\u201c\u914d\u89d2\u56e2\u961f\u201d&#xff0c;\u6309\u9700\u63d0\u4f9b\u529f\u80fd\u652f\u6301&#xff0c;\u53ef\u88ab\u591a\u4e2a\u201c\u4e3b\u89d2\u201d\u5171\u4eab\u3002<\/p>\n<h4>1.3 DLL\u7684\u6838\u5fc3\u4ef7\u503c<\/h4>\n<p>DLL\u7684\u8bbe\u8ba1\u521d\u8877\u662f\u89e3\u51b3\u65e9\u671f\u9759\u6001\u94fe\u63a5\u7684\u5f0a\u7aef&#xff0c;\u5176\u6838\u5fc3\u4ef7\u503c\u4f53\u73b0\u5728\u4e09\u4e2a\u65b9\u9762&#xff1a;<\/p>\n<li>\n<p>\u4ee3\u7801\u590d\u7528&#xff1a;\u591a\u4e2a\u7a0b\u5e8f\u53ef\u5171\u4eab\u540c\u4e00DLL\u4e2d\u7684\u51fd\u6570&#xff0c;\u65e0\u9700\u91cd\u590d\u7f16\u5199\u4ee3\u7801\u3002\u4f8b\u5982&#xff0c;user32.dll\u4e2d\u7684\u7a97\u53e3\u521b\u5efa\u51fd\u6570CreateWindow\u88ab\u6240\u6709Windows\u5e94\u7528\u5171\u4eab&#xff0c;\u907f\u514d\u4e86\u6bcf\u4e2a\u7a0b\u5e8f\u5355\u72ec\u5b9e\u73b0\u7a97\u53e3\u903b\u8f91\u7684\u5197\u4f59\u3002<\/p>\n<\/li>\n<li>\n<p>\u8d44\u6e90\u8282\u7701&#xff1a;DLL\u4ec5\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u88ab\u52a0\u8f7d\u5230\u5185\u5b58&#xff0c;\u4e14\u591a\u4e2a\u7a0b\u5e8f\u5171\u4eab\u540c\u4e00\u4efd\u7269\u7406\u5185\u5b58&#xff08;\u901a\u8fc7\u64cd\u4f5c\u7cfb\u7edf\u7684\u5185\u5b58\u6620\u5c04\u673a\u5236&#xff09;\u3002\u76f8\u6bd4\u9759\u6001\u94fe\u63a5&#xff08;\u4ee3\u7801\u88ab\u590d\u5236\u5230\u6bcf\u4e2aEXE\u4e2d&#xff09;&#xff0c;\u53ef\u663e\u8457\u51cf\u5c11\u78c1\u76d8\u7a7a\u95f4\u4e0e\u5185\u5b58\u5360\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>\u6a21\u5757\u5316\u4e0e\u53ef\u7ef4\u62a4\u6027&#xff1a;\u8f6f\u4ef6\u53ef\u6309\u529f\u80fd\u62c6\u5206\u4e3a\u591a\u4e2aDLL&#xff0c;\u4f8b\u5982\u4e00\u4e2a\u89c6\u9891\u64ad\u653e\u5668\u53ef\u62c6\u5206\u4e3adecoder.dll&#xff08;\u89e3\u7801&#xff09;\u3001ui.dll&#xff08;\u754c\u9762&#xff09;\u3001network.dll&#xff08;\u7f51\u7edc&#xff09;\u3002\u4fee\u6539\u67d0\u4e2aDLL\u65e0\u9700\u91cd\u65b0\u7f16\u8bd1\u6574\u4e2a\u7a0b\u5e8f&#xff0c;\u53ea\u9700\u66ff\u6362\u5bf9\u5e94\u6587\u4ef6\u5373\u53ef&#xff0c;\u6781\u5927\u964d\u4f4e\u4e86\u7ef4\u62a4\u6210\u672c\u3002<\/p>\n<\/li>\n<li>\n<p>\u7248\u672c\u72ec\u7acb\u66f4\u65b0&#xff1a;\u7cfb\u7edfDLL&#xff08;\u5982msvcrt.dll&#xff09;\u7684\u66f4\u65b0\u53ef\u72ec\u7acb\u4e8e\u4f9d\u8d56\u5b83\u7684\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u7528\u6237\u53ea\u9700\u5b89\u88c5DLL\u8865\u4e01&#xff0c;\u5373\u53ef\u4fee\u590d\u6f0f\u6d1e\u6216\u63d0\u5347\u6027\u80fd&#xff0c;\u65e0\u9700\u91cd\u65b0\u5b89\u88c5\u6240\u6709\u8f6f\u4ef6\u3002<\/p>\n<\/li>\n<h3>\u4e8c\u3001DLL\u7684\u5386\u53f2\u4e0e\u53d1\u5c55&#xff1a;\u4eceDOS\u5230\u73b0\u4ee3Windows<\/h3>\n<p>DLL\u5e76\u975e\u4e0e\u751f\u4ff1\u6765&#xff0c;\u5176\u53d1\u5c55\u4f34\u968fWindows\u64cd\u4f5c\u7cfb\u7edf\u7684\u6f14\u8fdb&#xff0c;\u7ecf\u5386\u4e86\u4ece\u65e0\u5230\u6709\u3001\u4ece\u7b80\u5355\u5230\u590d\u6742\u7684\u8fc7\u7a0b\u3002<\/p>\n<h4>2.1 \u9759\u6001\u94fe\u63a5\u65f6\u4ee3\u7684\u56f0\u5883&#xff08;1980s\u524d&#xff09;<\/h4>\n<p>\u5728DOS\u4e0e\u65e9\u671f\u64cd\u4f5c\u7cfb\u7edf\u4e2d&#xff0c;\u8f6f\u4ef6\u91c7\u7528\u201c\u9759\u6001\u94fe\u63a5\u201d\u6a21\u5f0f&#xff1a;\u7f16\u8bd1\u5668\u5c06\u7a0b\u5e8f\u4ee3\u7801\u4e0e\u4f9d\u8d56\u7684\u5e93&#xff08;\u5982\u6570\u5b66\u5e93\u3001\u8f93\u5165\u8f93\u51fa\u5e93&#xff09;\u5168\u90e8\u201c\u6253\u5305\u201d\u5230\u4e00\u4e2aEXE\u6587\u4ef6\u4e2d\u3002\u8fd9\u79cd\u65b9\u5f0f\u7684\u95ee\u9898\u663e\u800c\u6613\u89c1&#xff1a;<\/p>\n<ul>\n<li>\u5197\u4f59\u4e25\u91cd&#xff1a;\u6bcf\u4e2a\u7a0b\u5e8f\u90fd\u5305\u542b\u76f8\u540c\u7684\u5e93\u4ee3\u7801&#xff0c;\u4f8b\u598210\u4e2a\u7a0b\u5e8f\u90fd\u9700\u8981\u6253\u5370\u529f\u80fd&#xff0c;\u5c31\u4f1a\u670910\u4efd\u6253\u5370\u4ee3\u7801\u88ab\u590d\u5236\u5230\u5404\u81ea\u7684EXE\u4e2d&#xff0c;\u6d6a\u8d39\u78c1\u76d8\u4e0e\u5185\u5b58\u3002<\/li>\n<li>\u66f4\u65b0\u56f0\u96be&#xff1a;\u82e5\u5e93\u4ee3\u7801\u5b58\u5728\u6f0f\u6d1e&#xff0c;\u6240\u6709\u4f9d\u8d56\u5b83\u7684\u7a0b\u5e8f\u90fd\u9700\u91cd\u65b0\u7f16\u8bd1\u624d\u80fd\u4fee\u590d&#xff0c;\u7528\u6237\u9700\u9010\u4e2a\u66f4\u65b0\u8f6f\u4ef6&#xff0c;\u6210\u672c\u6781\u9ad8\u3002<\/li>\n<li>\u6269\u5c55\u6027\u5dee&#xff1a;\u7a0b\u5e8f\u529f\u80fd\u56fa\u5b9a&#xff0c;\u65e0\u6cd5\u901a\u8fc7\u6dfb\u52a0\u5916\u90e8\u6a21\u5757\u6269\u5c55&#xff0c;\u82e5\u9700\u65b0\u589e\u529f\u80fd&#xff0c;\u5fc5\u987b\u91cd\u65b0\u7f16\u8bd1\u6574\u4e2a\u7a0b\u5e8f\u3002<\/li>\n<\/ul>\n<h4>2.2 DLL\u7684\u8bde\u751f&#xff08;1980s\u672b-1990s&#xff09;<\/h4>\n<p>\u4e3a\u89e3\u51b3\u9759\u6001\u94fe\u63a5\u7684\u5f0a\u7aef&#xff0c;\u5fae\u8f6f\u57281987\u5e74\u63a8\u51fa\u7684Windows 2.0\u4e2d\u9996\u6b21\u5f15\u5165\u4e86DLL\u673a\u5236\u3002\u65e9\u671fDLL\u4ec5\u652f\u6301\u7b80\u5355\u7684\u51fd\u6570\u5171\u4eab&#xff0c;\u4e14\u529f\u80fd\u6709\u9650&#xff0c;\u4f46\u5df2\u5c55\u73b0\u51fa\u5de8\u5927\u6f5c\u529b\u3002<\/p>\n<p>1995\u5e74Windows 95\u7684\u53d1\u5e03&#xff0c;\u6807\u5fd7\u7740DLL\u8fdb\u5165\u6210\u719f\u9636\u6bb5&#xff1a;\u7cfb\u7edf\u5f15\u5165\u4e86\u6570\u767e\u4e2a\u6838\u5fc3DLL&#xff08;\u5982kernel32.dll\u3001gdi32.dll&#xff09;&#xff0c;\u5f62\u6210\u4e86\u5b8c\u6574\u7684\u52a8\u6001\u94fe\u63a5\u751f\u6001&#xff1b;\u540c\u65f6\u652f\u6301\u201c\u8d44\u6e90DLL\u201d&#xff08;\u5b58\u50a8\u56fe\u6807\u3001\u5b57\u7b26\u4e32\u7b49\u8d44\u6e90&#xff09;&#xff0c;\u8fdb\u4e00\u6b65\u63d0\u5347\u4e86\u6a21\u5757\u5316\u7a0b\u5ea6\u3002<\/p>\n<p>\u8fd9\u4e00\u65f6\u671f\u7684DLL\u4e3b\u8981\u9762\u5411C\/C&#043;&#043;\u7b49\u539f\u751f\u8bed\u8a00&#xff0c;\u4f9d\u8d56\u4e8eWindows\u7684PE\u683c\u5f0f\u4e0e\u5e95\u5c42\u5185\u5b58\u7ba1\u7406\u673a\u5236\u3002<\/p>\n<h4>2.3 \u6258\u7ba1DLL\u7684\u51fa\u73b0&#xff08;2000s\u540e&#xff09;<\/h4>\n<p>2002\u5e74.NET Framework\u53d1\u5e03\u540e&#xff0c;\u5fae\u8f6f\u5f15\u5165\u4e86\u201c\u6258\u7ba1DLL\u201d&#xff08;Managed DLL&#xff09;\u3002\u4e0e\u4f20\u7edf\u201c\u975e\u6258\u7ba1DLL\u201d&#xff08;Native DLL&#xff09;\u4e0d\u540c&#xff0c;\u6258\u7ba1DLL\u5305\u542b\u4e2d\u95f4\u8bed\u8a00&#xff08;IL&#xff09;\u4ee3\u7801&#xff0c;\u9700\u901a\u8fc7.NET\u865a\u62df\u673a&#xff08;CLR&#xff09;\u7f16\u8bd1\u4e3a\u673a\u5668\u7801\u540e\u6267\u884c&#xff0c;\u4f8b\u5982C#\u3001VB.NET\u751f\u6210\u7684DLL\u3002<\/p>\n<p>\u6258\u7ba1DLL\u7684\u51fa\u73b0\u6269\u5c55\u4e86DLL\u7684\u5e94\u7528\u573a\u666f&#xff1a;\u5b83\u4e0d\u4ec5\u652f\u6301\u8de8\u8bed\u8a00\u8c03\u7528&#xff08;C#\u53ef\u8c03\u7528VB.NET\u7684DLL&#xff09;&#xff0c;\u8fd8\u901a\u8fc7CLR\u5b9e\u73b0\u4e86\u81ea\u52a8\u5185\u5b58\u7ba1\u7406&#xff08;\u5783\u573e\u56de\u6536&#xff09;&#xff0c;\u964d\u4f4e\u4e86\u5185\u5b58\u6cc4\u6f0f\u98ce\u9669\u3002\u4f46\u6258\u7ba1DLL\u4f9d\u8d56.NET\u73af\u5883&#xff0c;\u65e0\u6cd5\u76f4\u63a5\u88ab\u975e\u6258\u7ba1\u7a0b\u5e8f&#xff08;\u5982\u7eafC&#043;&#043; EXE&#xff09;\u8c03\u7528&#xff0c;\u9700\u901a\u8fc7\u201c\u4e92\u64cd\u4f5c\u201d&#xff08;Interop&#xff09;\u673a\u5236\u6865\u63a5\u3002<\/p>\n<h4>2.4 \u73b0\u4ee3Windows\u4e2d\u7684DLL\u751f\u6001<\/h4>\n<p>\u5982\u4eca&#xff0c;DLL\u5df2\u6210\u4e3aWindows\u751f\u6001\u7684\u6838\u5fc3\u652f\u67f1&#xff1a;<\/p>\n<ul>\n<li>\u7cfb\u7edf\u7ea7DLL&#xff1a;\u7ea6\u6709500&#043;\u4e2a\u6838\u5fc3\u7cfb\u7edfDLL&#xff0c;\u8986\u76d6\u8fdb\u7a0b\u7ba1\u7406\u3001\u5185\u5b58\u64cd\u4f5c\u3001\u56fe\u5f62\u6e32\u67d3\u3001\u7f51\u7edc\u901a\u4fe1\u7b49\u57fa\u7840\u529f\u80fd&#xff0c;\u96c6\u4e2d\u5b58\u653e\u5728C:\\\\Windows\\\\System32\u4e0eC:\\\\Windows\\\\SysWOW64&#xff08;32\u4f4d\u517c\u5bb9&#xff09;\u76ee\u5f55\u3002<\/li>\n<li>\u7b2c\u4e09\u65b9DLL&#xff1a;\u51e0\u4e4e\u6240\u6709Windows\u5e94\u7528&#xff08;\u6d4f\u89c8\u5668\u3001\u529e\u516c\u8f6f\u4ef6\u3001\u6e38\u620f\u7b49&#xff09;\u90fd\u5305\u542b\u81ea\u5b9a\u4e49DLL&#xff0c;\u4f8b\u5982Chrome\u7684chrome.dll\u3001Office\u7684excel.exe\u4f9d\u8d56\u7684mso.dll\u3002<\/li>\n<li>\u8de8\u5e73\u53f0\u517c\u5bb9&#xff1a;\u5c3d\u7ba1DLL\u662fWindows\u7279\u6709\u683c\u5f0f&#xff0c;\u4f46\u5176\u4ed6\u7cfb\u7edf\u6709\u7c7b\u4f3c\u6280\u672f&#xff08;\u5982Linux\u7684.so\u3001macOS\u7684.dylib&#xff09;&#xff0c;\u5b83\u4eec\u7684\u8bbe\u8ba1\u601d\u60f3\u4e0eDLL\u4e00\u81f4&#xff0c;\u4ec5\u5728\u6587\u4ef6\u683c\u5f0f\u4e0e\u52a0\u8f7d\u673a\u5236\u4e0a\u6709\u5dee\u5f02\u3002<\/li>\n<\/ul>\n<h3>\u4e09\u3001DLL\u7684\u6587\u4ef6\u7ed3\u6784&#xff1a;PE\u683c\u5f0f\u4e0e\u6838\u5fc3\u7ec4\u6210<\/h3>\n<p>DLL\u672c\u8d28\u662fPE\u683c\u5f0f\u6587\u4ef6&#xff0c;\u5176\u5185\u90e8\u7ed3\u6784\u4e0eEXE\u9ad8\u5ea6\u76f8\u4f3c&#xff0c;\u4f46\u5b58\u5728\u9488\u5bf9\u52a8\u6001\u94fe\u63a5\u7684\u7279\u6b8a\u8bbe\u8ba1\u3002\u7406\u89e3PE\u683c\u5f0f\u662f\u638c\u63e1DLL\u5de5\u4f5c\u539f\u7406\u7684\u57fa\u7840\u3002<\/p>\n<h4>3.1 PE\u683c\u5f0f\u6982\u8ff0<\/h4>\n<p>PE&#xff08;Portable Executable&#xff09;\u662fWindows\u4e2dEXE\u3001DLL\u3001\u9a71\u52a8&#xff08;.sys&#xff09;\u7b49\u6587\u4ef6\u7684\u7edf\u4e00\u683c\u5f0f&#xff0c;\u5176\u8bbe\u8ba1\u76ee\u6807\u662f\u652f\u6301\u8de8\u786c\u4ef6\u5e73\u53f0&#xff08;\u5982x86\u3001x64&#xff09;\u4e0e\u64cd\u4f5c\u7cfb\u7edf&#xff08;Windows\u3001Xbox&#xff09;\u3002PE\u683c\u5f0f\u4ee5\u201c\u6bb5&#xff08;Section&#xff09;\u201d\u4e0e\u201c\u8868&#xff08;Table&#xff09;\u201d\u4e3a\u6838\u5fc3&#xff0c;\u524d\u8005\u5b58\u50a8\u5b9e\u9645\u6570\u636e&#xff08;\u4ee3\u7801\u3001\u53d8\u91cf\u7b49&#xff09;&#xff0c;\u540e\u8005\u5b58\u50a8\u5143\u4fe1\u606f&#xff08;\u5bfc\u5165\/\u5bfc\u51fa\u51fd\u6570\u3001\u8d44\u6e90\u4f4d\u7f6e\u7b49&#xff09;\u3002<\/p>\n<p>DLL\u7684PE\u7ed3\u6784\u53ef\u5206\u4e3a\u4e09\u4e2a\u5c42\u6b21&#xff1a;<\/p>\n<li>\n<p>DOS\u5934\u90e8\u4e0eDOS\u5b58\u6839&#xff1a;\u517c\u5bb9\u65e9\u671fDOS\u7cfb\u7edf&#xff0c;\u5305\u542be_magic&#xff08;\u6807\u8bc6\u201cMZ\u201d&#xff09;\u4e0ee_lfanew&#xff08;\u6307\u5411PE\u5934\u90e8\u7684\u504f\u79fb\u91cf&#xff09;\u3002\u73b0\u4ee3\u7cfb\u7edf\u52a0\u8f7d\u65f6\u4f1a\u8df3\u8fc7DOS\u5b58\u6839&#xff0c;\u76f4\u63a5\u89e3\u6790PE\u5934\u90e8\u3002<\/p>\n<\/li>\n<li>\n<p>PE\u5934\u90e8&#xff1a;\u5305\u542b\u6587\u4ef6\u7684\u6838\u5fc3\u5143\u4fe1\u606f&#xff0c;\u5206\u4e3a\u201c\u6807\u51c6PE\u5934\u90e8\u201d\u4e0e\u201c\u6269\u5c55PE\u5934\u90e8\u201d\u3002\u6807\u51c6\u5934\u90e8\u5b9a\u4e49\u76ee\u6807\u673a\u5668&#xff08;\u5982x86&#xff09;\u3001\u6587\u4ef6\u7c7b\u578b&#xff08;DLL\/EXE&#xff09;&#xff1b;\u6269\u5c55\u5934\u90e8\u5305\u542b\u5185\u5b58\u5206\u914d\u4fe1\u606f&#xff08;\u5982\u9ed8\u8ba4\u52a0\u8f7d\u5730\u5740&#xff09;\u3001\u6570\u636e\u76ee\u5f55\u8868&#xff08;\u6307\u5411\u5bfc\u5165\u8868\u3001\u5bfc\u51fa\u8868\u7b49\u5173\u952e\u7ed3\u6784&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u8282&#xff08;Sections&#xff09;&#xff1a;\u5b58\u50a8\u5b9e\u9645\u6570\u636e&#xff0c;\u6bcf\u4e2a\u8282\u6709\u660e\u786e\u7684\u7528\u9014\u4e0e\u5c5e\u6027&#xff08;\u5982\u53ef\u8bfb\u3001\u53ef\u5199\u3001\u53ef\u6267\u884c&#xff09;\u3002DLL\u4e2d\u5e38\u89c1\u7684\u8282\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>.text&#xff1a;\u5b58\u653e\u53ef\u6267\u884c\u4ee3\u7801&#xff08;\u51fd\u6570\u5b9e\u73b0&#xff09;&#xff0c;\u5c5e\u6027\u4e3a\u201c\u53ef\u8bfb\u3001\u53ef\u6267\u884c\u201d\u3002<\/li>\n<li>.data&#xff1a;\u5b58\u653e\u5df2\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf&#xff0c;\u5c5e\u6027\u4e3a\u201c\u53ef\u8bfb\u3001\u53ef\u5199\u201d\u3002<\/li>\n<li>.rdata&#xff1a;\u5b58\u653e\u53ea\u8bfb\u6570\u636e&#xff08;\u5982\u5b57\u7b26\u4e32\u5e38\u91cf\u3001\u5bfc\u5165\u8868\/\u5bfc\u51fa\u8868\u7684\u90e8\u5206\u4fe1\u606f&#xff09;&#xff0c;\u5c5e\u6027\u4e3a\u201c\u53ea\u8bfb\u201d\u3002<\/li>\n<li>.idata&#xff1a;\u5bfc\u5165\u8868&#xff08;Import Table&#xff09;&#xff0c;\u8bb0\u5f55\u8be5DLL\u4f9d\u8d56\u7684\u5176\u4ed6DLL\u53ca\u51fd\u6570\u3002<\/li>\n<li>.edata&#xff1a;\u5bfc\u51fa\u8868&#xff08;Export Table&#xff09;&#xff0c;\u8bb0\u5f55\u8be5DLL\u5bf9\u5916\u63d0\u4f9b\u7684\u51fd\u6570\u4e0e\u53d8\u91cf\u3002<\/li>\n<li>.reloc&#xff1a;\u91cd\u5b9a\u4f4d\u8868&#xff0c;\u7528\u4e8eDLL\u52a0\u8f7d\u5730\u5740\u4e0e\u9ed8\u8ba4\u5730\u5740\u4e0d\u7b26\u65f6\u4fee\u6b63\u4ee3\u7801\u4e2d\u7684\u5185\u5b58\u5730\u5740\u3002<\/li>\n<li>.rsrc&#xff1a;\u8d44\u6e90\u6570\u636e&#xff08;\u56fe\u6807\u3001\u5bf9\u8bdd\u6846\u3001\u5b57\u7b26\u4e32\u7b49&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<h4>3.2 \u5bfc\u51fa\u8868&#xff1a;DLL\u7684\u201c\u529f\u80fd\u6e05\u5355\u201d<\/h4>\n<p>\u5bfc\u51fa\u8868&#xff08;Export Table&#xff09;\u662fDLL\u7684\u6838\u5fc3\u7ec4\u4ef6&#xff0c;\u5b83\u5b9a\u4e49\u4e86DLL\u5bf9\u5916\u516c\u5f00\u7684\u51fd\u6570\u3001\u53d8\u91cf\u6216\u7c7b&#xff0c;\u4f9b\u5176\u4ed6\u6a21\u5757\u8c03\u7528\u3002\u5bfc\u51fa\u8868\u4f4d\u4e8e.edata\u8282&#xff0c;\u5176\u7ed3\u6784\u7531IMAGE_EXPORT_DIRECTORY\u7ed3\u6784\u4f53\u63cf\u8ff0&#xff08;\u5b9a\u4e49\u4e8ewinnt.h&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">_IMAGE_EXPORT_DIRECTORY<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    DWORD   Characteristics<span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ \u4fdd\u7559&#xff0c;\u901a\u5e38\u4e3a0<\/span><br \/>\n    DWORD   TimeDateStamp<span class=\"token punctuation\">;<\/span>        <span class=\"token comment\">\/\/ \u5bfc\u51fa\u8868\u521b\u5efa\u65f6\u95f4\u6233<\/span><br \/>\n    WORD    MajorVersion<span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/\/ \u4e3b\u7248\u672c\u53f7<\/span><br \/>\n    WORD    MinorVersion<span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/\/ \u6b21\u7248\u672c\u53f7<\/span><br \/>\n    DWORD   Name<span class=\"token punctuation\">;<\/span>                 <span class=\"token comment\">\/\/ DLL\u6587\u4ef6\u540d\u7684\u504f\u79fb\u91cf&#xff08;ASCII&#xff09;<\/span><br \/>\n    DWORD   Base<span class=\"token punctuation\">;<\/span>                 <span class=\"token comment\">\/\/ \u5bfc\u51fa\u51fd\u6570\u7684\u8d77\u59cb\u5e8f\u53f7<\/span><br \/>\n    DWORD   NumberOfFunctions<span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ \u5bfc\u51fa\u51fd\u6570\u603b\u6570<\/span><br \/>\n    DWORD   NumberOfNames<span class=\"token punctuation\">;<\/span>        <span class=\"token comment\">\/\/ \u6709\u540d\u79f0\u7684\u5bfc\u51fa\u51fd\u6570\u6570\u91cf<\/span><br \/>\n    DWORD   AddressOfFunctions<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u51fd\u6570\u5730\u5740\u6570\u7ec4&#xff08;RVA&#xff09;<\/span><br \/>\n    DWORD   AddressOfNames<span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ \u51fd\u6570\u540d\u79f0\u6570\u7ec4&#xff08;RVA&#xff0c;ASCII&#xff09;<\/span><br \/>\n    DWORD   AddressOfNameOrdinals<span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/ \u540d\u79f0\u4e0e\u5e8f\u53f7\u7684\u6620\u5c04\u6570\u7ec4&#xff08;WORD&#xff09;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span> IMAGE_EXPORT_DIRECTORY<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">*<\/span>PIMAGE_EXPORT_DIRECTORY<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5bfc\u51fa\u8868\u7684\u5de5\u4f5c\u903b\u8f91\u53ef\u6982\u62ec\u4e3a\u201c\u4e09\u6570\u7ec4\u4e00\u6620\u5c04\u201d&#xff1a;<\/p>\n<li>\n<p>\u51fd\u6570\u5730\u5740\u6570\u7ec4&#xff08;AddressOfFunctions&#xff09;&#xff1a;\u5b58\u50a8\u6bcf\u4e2a\u5bfc\u51fa\u51fd\u6570\u7684\u5185\u5b58\u5730\u5740&#xff08;\u76f8\u5bf9\u865a\u62df\u5730\u5740RVA&#xff09;&#xff0c;\u6309\u5e8f\u53f7\u6392\u5217\u3002\u4f8b\u5982&#xff0c;\u5e8f\u53f7\u4e3a1\u7684\u51fd\u6570\u5730\u5740\u5bf9\u5e94\u6570\u7ec4\u7b2c0\u4e2a\u5143\u7d20&#xff08;\u5e8f\u53f7&#061;Base&#043;\u7d22\u5f15&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u51fd\u6570\u540d\u79f0\u6570\u7ec4&#xff08;AddressOfNames&#xff09;&#xff1a;\u5b58\u50a8\u6709\u540d\u79f0\u7684\u5bfc\u51fa\u51fd\u6570\u7684\u540d\u79f0\u5b57\u7b26\u4e32\u5730\u5740&#xff08;RVA&#xff09;&#xff0c;\u6309\u540d\u79f0\u5b57\u6bcd\u5e8f\u6392\u5217\u3002<\/p>\n<\/li>\n<li>\n<p>\u540d\u79f0-\u5e8f\u53f7\u6620\u5c04\u6570\u7ec4&#xff08;AddressOfNameOrdinals&#xff09;&#xff1a;\u6bcf\u4e2a\u5143\u7d20\u662f\u4e00\u4e2a16\u4f4d\u6574\u6570&#xff0c;\u8868\u793a\u540d\u79f0\u6570\u7ec4\u4e2d\u5bf9\u5e94\u51fd\u6570\u5728\u201c\u51fd\u6570\u5730\u5740\u6570\u7ec4\u201d\u4e2d\u7684\u7d22\u5f15&#xff08;\u5373\u5e8f\u53f7&#061;Base&#043;\u7d22\u5f15&#xff09;\u3002<\/p>\n<\/li>\n<p>\u4f8b\u5982&#xff0c;\u82e5AddressOfNames\u7684\u7b2c0\u4e2a\u5143\u7d20\u6307\u5411\u5b57\u7b26\u4e32\u201cAdd\u201d&#xff0c;AddressOfNameOrdinals\u7684\u7b2c0\u4e2a\u5143\u7d20\u4e3a2&#xff0c;\u5219\u201cAdd\u201d\u51fd\u6570\u5bf9\u5e94AddressOfFunctions\u7684\u7b2c2\u4e2a\u5143\u7d20&#xff08;\u5730\u5740&#xff09;&#xff0c;\u5176\u5e8f\u53f7\u4e3aBase &#043; 2\u3002<\/p>\n<p>\u5bfc\u51fa\u8868\u7684\u5b58\u5728\u4f7fDLL\u65e0\u9700\u66b4\u9732\u6e90\u4ee3\u7801&#xff0c;\u53ea\u9700\u901a\u8fc7\u5bfc\u51fa\u8868\u58f0\u660e\u53ef\u8c03\u7528\u7684\u529f\u80fd&#xff0c;\u5b9e\u73b0\u4e86\u201c\u9ed1\u7bb1\u590d\u7528\u201d\u3002<\/p>\n<h4>3.3 \u5bfc\u5165\u8868&#xff1a;DLL\u7684\u201c\u4f9d\u8d56\u6e05\u5355\u201d<\/h4>\n<p>\u5bfc\u5165\u8868&#xff08;Import Table&#xff09;\u8bb0\u5f55\u4e86\u5f53\u524dDLL&#xff08;\u6216EXE&#xff09;\u4f9d\u8d56\u7684\u5176\u4ed6DLL\u53ca\u51fd\u6570&#xff0c;\u786e\u4fdd\u52a0\u8f7d\u65f6\u80fd\u627e\u5230\u6240\u9700\u7684\u5916\u90e8\u529f\u80fd\u3002\u5bfc\u5165\u8868\u4f4d\u4e8e.idata\u8282&#xff0c;\u7531IMAGE_IMPORT_DESCRIPTOR\u7ed3\u6784\u4f53\u6570\u7ec4\u63cf\u8ff0&#xff1a;<\/p>\n<p><span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">_IMAGE_IMPORT_DESCRIPTOR<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">union<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        DWORD   Characteristics<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ 0&#xff08;\u672a\u4f7f\u7528&#xff09;<\/span><br \/>\n        DWORD   OriginalFirstThunk<span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/ \u6307\u5411\u5bfc\u5165\u540d\u79f0\u8868&#xff08;INT&#xff09;\u7684RVA<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> DUMMYUNIONNAME<span class=\"token punctuation\">;<\/span><br \/>\n    DWORD   TimeDateStamp<span class=\"token punctuation\">;<\/span>        <span class=\"token comment\">\/\/ \u5bfc\u5165\u6a21\u5757\u7684\u65f6\u95f4\u6233&#xff08;0\u8868\u793a\u672a\u7ed1\u5b9a&#xff09;<\/span><br \/>\n    DWORD   ForwarderChain<span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ \u8f6c\u53d1\u94fe&#xff08;\u901a\u5e38\u4e3a0&#xff09;<\/span><br \/>\n    DWORD   Name<span class=\"token punctuation\">;<\/span>                 <span class=\"token comment\">\/\/ \u4f9d\u8d56DLL\u540d\u79f0\u7684RVA&#xff08;ASCII&#xff09;<\/span><br \/>\n    DWORD   FirstThunk<span class=\"token punctuation\">;<\/span>           <span class=\"token comment\">\/\/ \u6307\u5411\u5bfc\u5165\u5730\u5740\u8868&#xff08;IAT&#xff09;\u7684RVA<\/span><br \/>\n<span class=\"token punctuation\">}<\/span> IMAGE_IMPORT_DESCRIPTOR<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">*<\/span>PIMAGE_IMPORT_DESCRIPTOR<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6bcf\u4e2aIMAGE_IMPORT_DESCRIPTOR\u5bf9\u5e94\u4e00\u4e2a\u4f9d\u8d56\u7684DLL&#xff0c;\u5176\u6838\u5fc3\u662f\u4e24\u4e2a\u8868&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5bfc\u5165\u540d\u79f0\u8868&#xff08;INT&#xff0c;OriginalFirstThunk\u6307\u5411&#xff09;&#xff1a;\u5b58\u50a8\u4f9d\u8d56\u51fd\u6570\u7684\u540d\u79f0\u6216\u5e8f\u53f7&#xff08;IMAGE_THUNK_DATA\u7ed3\u6784\u4f53&#xff09;&#xff0c;\u7528\u4e8e\u52a0\u8f7d\u65f6\u67e5\u627e\u51fd\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>\u5bfc\u5165\u5730\u5740\u8868&#xff08;IAT&#xff0c;FirstThunk\u6307\u5411&#xff09;&#xff1a;\u521d\u59cb\u65f6\u4e0eINT\u5185\u5bb9\u76f8\u540c&#xff0c;\u52a0\u8f7d\u540e\u88ab\u66ff\u6362\u4e3a\u51fd\u6570\u7684\u5b9e\u9645\u5185\u5b58\u5730\u5740&#xff0c;\u4f9b\u7a0b\u5e8f\u76f4\u63a5\u8c03\u7528&#xff08;\u907f\u514d\u6bcf\u6b21\u8c03\u7528\u90fd\u67e5\u8be2\u5bfc\u51fa\u8868&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4f8b\u5982&#xff0c;\u82e5\u7a0b\u5e8f\u4f9d\u8d56kernel32.dll\u7684CreateFileA\u51fd\u6570&#xff0c;\u5219\u5bfc\u5165\u8868\u4e2d\u4f1a\u6709\u4e00\u4e2aIMAGE_IMPORT_DESCRIPTOR\u6307\u5411kernel32.dll&#xff0c;\u5176INT\u5305\u542b\u201cCreateFileA\u201d\u7684\u540d\u79f0&#xff0c;IAT\u5728\u52a0\u8f7d\u540e\u88ab\u586b\u5145\u4e3a\u8be5\u51fd\u6570\u7684\u5b9e\u9645\u5730\u5740\u3002<\/p>\n<p>\u5bfc\u5165\u8868\u4f7f\u7a0b\u5e8f\u80fd\u201c\u58f0\u660e\u4f9d\u8d56\u201d\u800c\u975e\u201c\u786c\u7f16\u7801\u5730\u5740\u201d&#xff0c;\u5b9e\u73b0\u4e86\u8c03\u7528\u8005\u4e0e\u88ab\u8c03\u7528\u8005\u7684\u89e3\u8026\u3002<\/p>\n<h4>3.4 \u91cd\u5b9a\u4f4d\u8868&#xff1a;\u89e3\u51b3\u201c\u5730\u5740\u51b2\u7a81\u201d\u7684\u5173\u952e<\/h4>\n<p>DLL\u5728\u7f16\u8bd1\u65f6\u4f1a\u88ab\u5206\u914d\u4e00\u4e2a\u201c\u9ed8\u8ba4\u52a0\u8f7d\u5730\u5740\u201d&#xff08;\u59820x10000000&#xff09;&#xff0c;\u4f46\u5b9e\u9645\u52a0\u8f7d\u65f6\u53ef\u80fd\u56e0\u5730\u5740\u88ab\u5360\u7528\u800c\u65e0\u6cd5\u4f7f\u7528&#xff08;\u4f8b\u5982\u4e24\u4e2aDLL\u9ed8\u8ba4\u5730\u5740\u76f8\u540c&#xff09;\u3002\u6b64\u65f6&#xff0c;\u91cd\u5b9a\u4f4d\u8868&#xff08;Relocation Table&#xff09;\u4f1a\u4fee\u6b63\u4ee3\u7801\u4e2d\u786c\u7f16\u7801\u7684\u5185\u5b58\u5730\u5740&#xff0c;\u786e\u4fdd\u7a0b\u5e8f\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<p>\u91cd\u5b9a\u4f4d\u8868\u4f4d\u4e8e.reloc\u8282&#xff0c;\u7531IMAGE_BASE_RELOCATION\u7ed3\u6784\u4f53\u6570\u7ec4\u7ec4\u6210&#xff1a;<\/p>\n<p><span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">_IMAGE_BASE_RELOCATION<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    DWORD   VirtualAddress<span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ \u91cd\u5b9a\u4f4d\u5757\u7684\u8d77\u59cbRVA<\/span><br \/>\n    DWORD   SizeOfBlock<span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ \u5757\u5927\u5c0f&#xff08;\u5305\u542b\u672c\u7ed3\u6784\u4f53&#xff09;<\/span><br \/>\n    <span class=\"token comment\">\/\/ WORD    TypeOffset[1];      \/\/ \u91cd\u5b9a\u4f4d\u9879&#xff08;\u7c7b\u578b&#043;\u504f\u79fb&#xff09;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span> IMAGE_BASE_RELOCATION<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">*<\/span>PIMAGE_BASE_RELOCATION<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6bcf\u4e2a\u91cd\u5b9a\u4f4d\u5757\u5305\u542b\u591a\u4e2a16\u4f4d\u7684\u201c\u91cd\u5b9a\u4f4d\u9879\u201d&#xff0c;\u9ad84\u4f4d\u8868\u793a\u91cd\u5b9a\u4f4d\u7c7b\u578b&#xff08;\u5982IMAGE_REL_BASED_HIGHLOW\u8868\u793a32\u4f4d\u5730\u5740&#xff09;&#xff0c;\u4f4e12\u4f4d\u8868\u793a\u9700\u4fee\u6b63\u7684\u5730\u5740\u5728\u5757\u5185\u7684\u504f\u79fb\u3002<\/p>\n<p>\u4f8b\u5982&#xff0c;\u82e5DLL\u9ed8\u8ba4\u5730\u5740\u4e3a0x10000000&#xff0c;\u5b9e\u9645\u52a0\u8f7d\u52300x20000000&#xff08;\u504f\u79fb0x10000000&#xff09;&#xff0c;\u5219\u91cd\u5b9a\u4f4d\u9879\u4f1a\u5c06\u4ee3\u7801\u4e2d\u6240\u6709\u57fa\u4e8e0x10000000\u7684\u5730\u5740\u52a0\u4e0a0x10000000&#xff0c;\u4fee\u6b63\u4e3a0x20000000\u5f00\u5934\u7684\u5b9e\u9645\u5730\u5740\u3002<\/p>\n<p>\u91cd\u5b9a\u4f4d\u8868\u662fDLL\u201c\u52a8\u6001\u9002\u914d\u201d\u5185\u5b58\u73af\u5883\u7684\u6838\u5fc3\u673a\u5236&#xff0c;\u786e\u4fdd\u4e86\u591a\u4e2aDLL\u5728\u540c\u4e00\u8fdb\u7a0b\u4e2d\u53ef\u5171\u5b58\u3002<\/p>\n<h3>\u56db\u3001DLL\u7684\u5de5\u4f5c\u539f\u7406&#xff1a;\u4ece\u52a0\u8f7d\u5230\u6267\u884c\u7684\u5b8c\u6574\u6d41\u7a0b<\/h3>\n<p>DLL\u7684\u751f\u547d\u5468\u671f\u4ece\u88ab\u8c03\u7528\u7a0b\u5e8f\u8bf7\u6c42\u52a0\u8f7d\u5f00\u59cb&#xff0c;\u5230\u7a0b\u5e8f\u9000\u51fa\u65f6\u5378\u8f7d\u7ed3\u675f&#xff0c;\u6d89\u53ca\u52a0\u8f7d\u3001\u94fe\u63a5\u3001\u6267\u884c\u3001\u5378\u8f7d\u56db\u4e2a\u9636\u6bb5&#xff0c;\u6bcf\u4e2a\u9636\u6bb5\u90fd\u4f9d\u8d56\u64cd\u4f5c\u7cfb\u7edf\u7684\u6838\u5fc3\u673a\u5236\u3002<\/p>\n<h4>4.1 DLL\u7684\u52a0\u8f7d\u673a\u5236<\/h4>\n<p>DLL\u7684\u52a0\u8f7d\u662f\u6307\u5c06\u6587\u4ef6\u5185\u5bb9\u6620\u5c04\u5230\u8c03\u7528\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4&#xff0c;\u5e76\u5b8c\u6210\u521d\u59cb\u5316\u7684\u8fc7\u7a0b&#xff0c;\u5206\u4e3a\u201c\u9759\u6001\u52a0\u8f7d\u201d\u4e0e\u201c\u52a8\u6001\u52a0\u8f7d\u201d\u4e24\u79cd\u65b9\u5f0f\u3002<\/p>\n<h5>4.1.1 \u9759\u6001\u52a0\u8f7d&#xff08;\u9690\u5f0f\u94fe\u63a5&#xff09;<\/h5>\n<p>\u9759\u6001\u52a0\u8f7d\u662f\u6307\u7a0b\u5e8f\u5728\u7f16\u8bd1\u65f6\u901a\u8fc7\u5bfc\u5165\u5e93&#xff08;.lib&#xff09;\u58f0\u660e\u5bf9DLL\u7684\u4f9d\u8d56&#xff0c;\u64cd\u4f5c\u7cfb\u7edf\u5728\u7a0b\u5e8f\u542f\u52a8\u65f6\u81ea\u52a8\u52a0\u8f7d\u6240\u9700DLL\u3002\u5176\u6d41\u7a0b\u5982\u4e0b&#xff1a;<\/p>\n<li>\n<p>\u7f16\u8bd1\u9636\u6bb5&#xff1a;\u5f00\u53d1\u8005\u5728\u4ee3\u7801\u4e2d\u7528__declspec(dllimport)\u58f0\u660e\u5bfc\u5165\u51fd\u6570&#xff08;\u5982extern &#034;C&#034; __declspec(dllimport) int Add(int a, int b);&#xff09;&#xff0c;\u5e76\u94fe\u63a5DLL\u7684\u5bfc\u5165\u5e93&#xff08;.lib&#xff09;\u3002\u5bfc\u5165\u5e93\u4e0d\u5305\u542b\u5b9e\u9645\u4ee3\u7801&#xff0c;\u4ec5\u8bb0\u5f55DLL\u540d\u79f0\u4e0e\u5bfc\u51fa\u51fd\u6570\u4fe1\u606f&#xff0c;\u7528\u4e8e\u751f\u6210\u7a0b\u5e8f\u7684\u5bfc\u5165\u8868\u3002<\/p>\n<\/li>\n<li>\n<p>\u542f\u52a8\u9636\u6bb5&#xff1a;\u7a0b\u5e8f&#xff08;EXE&#xff09;\u88ab\u53cc\u51fb\u540e&#xff0c;\u64cd\u4f5c\u7cfb\u7edf\u521b\u5efa\u8fdb\u7a0b\u5e76\u52a0\u8f7dEXE\u5230\u5185\u5b58&#xff0c;\u7136\u540e\u89e3\u6790\u5176\u5bfc\u5165\u8868&#xff0c;\u6309\u4f9d\u8d56\u987a\u5e8f\u52a0\u8f7d\u6240\u6709DLL&#xff1a;<\/p>\n<ul>\n<li>\u67e5\u627eDLL\u6587\u4ef6&#xff1a;\u6309\u201c\u641c\u7d22\u8def\u5f84\u201d&#xff08;\u5f53\u524d\u76ee\u5f55\u2192\u7cfb\u7edf\u76ee\u5f55\u2192\u73af\u5883\u53d8\u91cfPATH&#xff09;\u67e5\u627eDLL\u3002<\/li>\n<li>\u6620\u5c04\u5230\u5185\u5b58&#xff1a;\u627e\u5230DLL\u540e&#xff0c;\u901a\u8fc7\u5185\u5b58\u6620\u5c04&#xff08;CreateFileMapping&#043;MapViewOfFile&#xff09;\u5c06\u5176\u52a0\u8f7d\u5230\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4&#xff08;\u4f18\u5148\u4f7f\u7528\u9ed8\u8ba4\u5730\u5740&#xff0c;\u51b2\u7a81\u5219\u91cd\u5b9a\u4f4d&#xff09;\u3002<\/li>\n<li>\u9012\u5f52\u52a0\u8f7d\u4f9d\u8d56&#xff1a;\u82e5\u88ab\u52a0\u8f7d\u7684DLL\u8fd8\u6709\u81ea\u8eab\u7684\u5bfc\u5165\u8868&#xff0c;\u91cd\u590d\u4e0a\u8ff0\u6b65\u9aa4\u52a0\u8f7d\u5176\u4f9d\u8d56\u7684DLL&#xff08;\u5f62\u6210\u201cDLL\u4f9d\u8d56\u94fe\u201d&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u94fe\u63a5\u9636\u6bb5&#xff1a;\u6240\u6709DLL\u52a0\u8f7d\u5b8c\u6210\u540e&#xff0c;\u64cd\u4f5c\u7cfb\u7edf\u904d\u5386\u7a0b\u5e8f\u7684\u5bfc\u5165\u8868&#xff0c;\u5c06\u6bcf\u4e2a\u5bfc\u5165\u51fd\u6570\u7684\u5730\u5740\u66ff\u6362\u4e3aDLL\u5bfc\u51fa\u8868\u4e2d\u7684\u5b9e\u9645\u5730\u5740&#xff08;\u586b\u5145IAT&#xff09;&#xff0c;\u4f7f\u7a0b\u5e8f\u53ef\u76f4\u63a5\u8c03\u7528\u3002<\/p>\n<\/li>\n<p>\u9759\u6001\u52a0\u8f7d\u7684\u4f18\u52bf\u662f\u7b80\u5355&#xff08;\u5f00\u53d1\u8005\u65e0\u9700\u624b\u52a8\u5904\u7406\u52a0\u8f7d\u903b\u8f91&#xff09;&#xff0c;\u4f46\u7f3a\u70b9\u662f\u4f9d\u8d56\u7684DLL\u7f3a\u5931\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u542f\u52a8\u5931\u8d25&#xff08;\u5f39\u51fa\u201c\u627e\u4e0d\u5230xxx.dll\u201d\u9519\u8bef&#xff09;\u3002<\/p>\n<h5>4.1.2 \u52a8\u6001\u52a0\u8f7d&#xff08;\u663e\u5f0f\u94fe\u63a5&#xff09;<\/h5>\n<p>\u52a8\u6001\u52a0\u8f7d\u662f\u6307\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u901a\u8fc7API\u624b\u52a8\u52a0\u8f7dDLL\u3001\u83b7\u53d6\u51fd\u6570\u5730\u5740&#xff0c;\u4f7f\u7528\u5b8c\u6bd5\u540e\u624b\u52a8\u5378\u8f7d\u3002\u6838\u5fc3API\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>LoadLibraryA\/W&#xff1a;\u52a0\u8f7dDLL\u5e76\u8fd4\u56de\u5176\u53e5\u67c4&#xff08;HMODULE&#xff09;\u3002<\/li>\n<li>GetProcAddress&#xff1a;\u901a\u8fc7DLL\u53e5\u67c4\u4e0e\u51fd\u6570\u540d\u79f0\/\u5e8f\u53f7\u83b7\u53d6\u51fd\u6570\u5730\u5740\u3002<\/li>\n<li>FreeLibrary&#xff1a;\u5378\u8f7dDLL&#xff0c;\u51cf\u5c11\u5176\u5f15\u7528\u8ba1\u6570&#xff08;\u8ba1\u6570\u4e3a0\u65f6\u5b9e\u9645\u91ca\u653e\u5185\u5b58&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u52a8\u6001\u52a0\u8f7d\u7684\u6d41\u7a0b\u793a\u4f8b&#xff08;C&#043;&#043;&#xff09;&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ \u52a8\u6001\u52a0\u8f7dDLL<\/span><br \/>\nHMODULE hDll <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">LoadLibraryA<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;MyMath.dll&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>hDll <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u52a0\u8f7d\u5931\u8d25&#xff08;\u5982\u6587\u4ef6\u4e0d\u5b58\u5728&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token function\">GetLastError<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u83b7\u53d6\u5bfc\u51fa\u51fd\u6570\u5730\u5740<\/span><br \/>\n<span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">int<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span>AddFunc<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u5b9a\u4e49\u51fd\u6570\u6307\u9488\u7c7b\u578b<\/span><br \/>\nAddFunc add <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span>AddFunc<span class=\"token punctuation\">)<\/span><span class=\"token function\">GetProcAddress<\/span><span class=\"token punctuation\">(<\/span>hDll<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;Add&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>add <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">FreeLibrary<\/span><span class=\"token punctuation\">(<\/span>hDll<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token function\">GetLastError<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u8c03\u7528\u51fd\u6570<\/span><br \/>\n<span class=\"token keyword\">int<\/span> result <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">add<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u8f93\u51fa5<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u5378\u8f7dDLL<\/span><br \/>\n<span class=\"token function\">FreeLibrary<\/span><span class=\"token punctuation\">(<\/span>hDll<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u52a8\u6001\u52a0\u8f7d\u7684\u4f18\u52bf\u662f\u7075\u6d3b\u6027\u9ad8&#xff1a;\u53ef\u5728\u9700\u8981\u65f6\u624d\u52a0\u8f7dDLL&#xff08;\u51cf\u5c11\u542f\u52a8\u65f6\u95f4&#xff09;&#xff0c;\u4e14\u80fd\u5904\u7406DLL\u7f3a\u5931\u7684\u60c5\u51b5&#xff08;\u4f8b\u5982\u63d0\u793a\u7528\u6237\u5b89\u88c5\u4f9d\u8d56&#xff09;&#xff1b;\u7f3a\u70b9\u662f\u9700\u624b\u52a8\u7ba1\u7406\u52a0\u8f7d\/\u5378\u8f7d\u903b\u8f91&#xff0c;\u4e14\u51fd\u6570\u8c03\u7528\u9700\u901a\u8fc7\u6307\u9488&#xff08;\u589e\u52a0\u4ee3\u7801\u590d\u6742\u5ea6&#xff09;\u3002<\/p>\n<h4>4.2 DLL\u7684\u5185\u5b58\u6620\u5c04\u4e0e\u5171\u4eab\u673a\u5236<\/h4>\n<p>DLL\u88ab\u52a0\u8f7d\u540e\u5e76\u975e\u5728\u5185\u5b58\u4e2d\u590d\u5236\u591a\u4efd&#xff0c;\u800c\u662f\u901a\u8fc7\u64cd\u4f5c\u7cfb\u7edf\u7684\u201c\u5185\u5b58\u6620\u5c04\u6587\u4ef6&#xff08;Memory-Mapped File&#xff09;\u201d\u673a\u5236\u5b9e\u73b0\u9ad8\u6548\u5171\u4eab&#xff0c;\u5176\u6838\u5fc3\u903b\u8f91\u5982\u4e0b&#xff1a;<\/p>\n<li>\n<p>\u7269\u7406\u5185\u5b58\u4e0e\u865a\u62df\u5185\u5b58\u5206\u79bb&#xff1a;Windows\u4f7f\u7528\u865a\u62df\u5185\u5b58\u7ba1\u7406&#xff0c;\u6bcf\u4e2a\u8fdb\u7a0b\u6709\u72ec\u7acb\u76844GB&#xff08;32\u4f4d&#xff09;\u6216\u66f4\u5927&#xff08;64\u4f4d&#xff09;\u865a\u62df\u5730\u5740\u7a7a\u95f4&#xff0c;\u4f46\u7269\u7406\u5185\u5b58\u662f\u6240\u6709\u8fdb\u7a0b\u5171\u4eab\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>DLL\u7684\u201c\u5199\u65f6\u590d\u5236\u201d&#xff1a;DLL\u7684.text&#xff08;\u4ee3\u7801&#xff09;\u7b49\u53ea\u8bfb\u8282\u88ab\u591a\u4e2a\u8fdb\u7a0b\u6620\u5c04\u5230\u5404\u81ea\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4&#xff0c;\u4f46\u6307\u5411\u540c\u4e00\u4efd\u7269\u7406\u5185\u5b58&#xff08;\u5b9e\u73b0\u201c\u53ea\u8bfb\u5171\u4eab\u201d&#xff09;&#xff1b;\u82e5\u67d0\u8fdb\u7a0b\u4fee\u6539\u4e86DLL\u7684.data&#xff08;\u53ef\u5199\u6570\u636e&#xff09;&#xff0c;\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u4e3a\u8be5\u8fdb\u7a0b\u590d\u5236\u4e00\u4efd\u4fee\u6539\u540e\u7684\u9875\u9762&#xff08;\u7269\u7406\u5185\u5b58&#xff09;&#xff0c;\u5176\u4ed6\u8fdb\u7a0b\u4ecd\u4f7f\u7528\u539f\u59cb\u9875\u9762&#xff08;\u5373\u201c\u5199\u65f6\u590d\u5236\u201d&#xff0c;Copy-on-Write&#xff09;&#xff0c;\u786e\u4fdd\u8fdb\u7a0b\u95f4\u6570\u636e\u9694\u79bb\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f15\u7528\u8ba1\u6570\u7ba1\u7406&#xff1a;\u6bcf\u4e2aDLL\u88ab\u52a0\u8f7d\u65f6\u5f15\u7528\u8ba1\u6570&#043;1&#xff0c;FreeLibrary\u6216\u8fdb\u7a0b\u9000\u51fa\u65f6-1&#xff1b;\u4ec5\u5f53\u8ba1\u6570\u4e3a0\u65f6&#xff0c;DLL\u7684\u7269\u7406\u5185\u5b58\u624d\u4f1a\u88ab\u91ca\u653e&#xff0c;\u907f\u514d\u88ab\u6b63\u5728\u4f7f\u7528\u7684\u8fdb\u7a0b\u610f\u5916\u5378\u8f7d\u3002<\/p>\n<\/li>\n<p>\u8fd9\u79cd\u673a\u5236\u4f7f100\u4e2a\u8fdb\u7a0b\u52a0\u8f7d\u540c\u4e00DLL\u65f6&#xff0c;\u7269\u7406\u5185\u5b58\u4e2d\u4ec5\u9700\u5b58\u50a8\u4e00\u4efdDLL\u4ee3\u7801&#xff0c;\u6781\u5927\u8282\u7701\u4e86\u8d44\u6e90\u3002\u4f8b\u5982&#xff0c;kernel32.dll\u5728\u7cfb\u7edf\u542f\u52a8\u540e\u88ab\u6240\u6709\u8fdb\u7a0b\u5171\u4eab&#xff0c;\u7269\u7406\u5185\u5b58\u5360\u7528\u4ec5\u7ea61MB&#xff0c;\u800c\u975e100MB\u3002<\/p>\n<h4>4.3 DllMain&#xff1a;DLL\u7684\u201c\u751f\u547d\u5468\u671f\u7ba1\u7406\u5668\u201d<\/h4>\n<p>DllMain\u662fDLL\u7684\u53ef\u9009\u5165\u53e3\u51fd\u6570&#xff0c;\u7528\u4e8e\u5728DLL\u52a0\u8f7d\u3001\u5378\u8f7d\u6216\u8fdb\u7a0b\/\u7ebf\u7a0b\u72b6\u6001\u53d8\u5316\u65f6\u6267\u884c\u521d\u59cb\u5316\u6216\u6e05\u7406\u64cd\u4f5c&#xff0c;\u5176\u539f\u578b\u4e3a&#xff1a;<\/p>\n<p>BOOL WINAPI <span class=\"token function\">DllMain<\/span><span class=\"token punctuation\">(<\/span><br \/>\n    HINSTANCE hinstDLL<span class=\"token punctuation\">,<\/span>  <span class=\"token comment\">\/\/ DLL\u5b9e\u4f8b\u53e5\u67c4&#xff08;\u4e0eHMODULE\u76f8\u540c&#xff09;<\/span><br \/>\n    DWORD fdwReason<span class=\"token punctuation\">,<\/span>     <span class=\"token comment\">\/\/ \u8c03\u7528\u539f\u56e0<\/span><br \/>\n    LPVOID lpvReserved   <span class=\"token comment\">\/\/ \u4fdd\u7559\u53c2\u6570&#xff08;\u7ebf\u7a0b\u76f8\u5173\u65f6\u4e3a\u7ebf\u7a0bID&#xff09;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>fdwReason\u53c2\u6570\u51b3\u5b9a\u4e86DllMain\u7684\u6267\u884c\u65f6\u673a&#xff0c;\u4e3b\u8981\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>\n<p>DLL_PROCESS_ATTACH&#xff1a;DLL\u88ab\u52a0\u8f7d\u5230\u8fdb\u7a0b\u65f6\u8c03\u7528&#xff08;\u8fdb\u7a0b\u9996\u6b21\u52a0\u8f7d&#xff09;&#xff0c;\u53ef\u7528\u4e8e\u521d\u59cb\u5316\u5168\u5c40\u53d8\u91cf\u3001\u5206\u914d\u8d44\u6e90&#xff08;\u5982\u521b\u5efa\u4e92\u65a5\u4f53&#xff09;\u3002\u8fd4\u56deTRUE\u8868\u793a\u521d\u59cb\u5316\u6210\u529f&#xff0c;FALSE\u4f1a\u5bfc\u81f4\u52a0\u8f7d\u5931\u8d25\u3002<\/p>\n<\/li>\n<li>\n<p>DLL_PROCESS_DETACH&#xff1a;DLL\u88ab\u5378\u8f7d&#xff08;\u8fdb\u7a0b\u9000\u51fa\u6216FreeLibrary\u4e14\u5f15\u7528\u8ba1\u6570\u4e3a0&#xff09;\u65f6\u8c03\u7528&#xff0c;\u7528\u4e8e\u91ca\u653eDLL_PROCESS_ATTACH\u4e2d\u5206\u914d\u7684\u8d44\u6e90&#xff08;\u5982\u5173\u95ed\u6587\u4ef6\u53e5\u67c4&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>DLL_THREAD_ATTACH&#xff1a;\u8fdb\u7a0b\u4e2d\u521b\u5efa\u65b0\u7ebf\u7a0b\u65f6\u8c03\u7528&#xff0c;\u53ef\u7528\u4e8e\u521d\u59cb\u5316\u7ebf\u7a0b\u5c40\u90e8\u5b58\u50a8&#xff08;TLS&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>DLL_THREAD_DETACH&#xff1a;\u7ebf\u7a0b\u9000\u51fa\u65f6\u8c03\u7528&#xff0c;\u7528\u4e8e\u6e05\u7406\u7ebf\u7a0b\u5c40\u90e8\u8d44\u6e90\u3002<\/p>\n<\/li>\n<\/ul>\n<p>DllMain\u7684\u8bbe\u8ba1\u9700\u8c28\u614e&#xff0c;\u56e0\u5176\u5728\u8fdb\u7a0b\/\u7ebf\u7a0b\u7684\u5173\u952e\u9636\u6bb5\u6267\u884c&#xff0c;\u82e5\u5305\u542b\u590d\u6742\u64cd\u4f5c&#xff08;\u5982\u52a0\u8f7d\u5176\u4ed6DLL\u3001\u8c03\u7528\u540c\u6b65\u51fd\u6570&#xff09;\u53ef\u80fd\u5bfc\u81f4\u6b7b\u9501\u6216\u5d29\u6e83\u3002\u4f8b\u5982&#xff0c;\u5728DLL_PROCESS_ATTACH\u4e2d\u8c03\u7528LoadLibrary\u53ef\u80fd\u89e6\u53d1\u5d4c\u5957\u52a0\u8f7d&#xff0c;\u5bfc\u81f4\u7cfb\u7edf\u9501\u7b49\u5f85&#xff1b;\u5728DLL_THREAD_ATTACH\u4e2d\u4f7f\u7528CreateThread\u53ef\u80fd\u5f15\u53d1\u9012\u5f52\u8c03\u7528\u3002<\/p>\n<p>\u6700\u4f73\u5b9e\u8df5\u662f&#xff1a;DllMain\u4ec5\u6267\u884c\u7b80\u5355\u521d\u59cb\u5316&#xff08;\u5982\u53d8\u91cf\u8d4b\u503c&#xff09;&#xff0c;\u590d\u6742\u903b\u8f91\u5e94\u653e\u5728\u5355\u72ec\u7684\u521d\u59cb\u5316\u51fd\u6570\u4e2d&#xff08;\u7531\u8c03\u7528\u8005\u663e\u5f0f\u8c03\u7528&#xff09;\u3002<\/p>\n<h4>4.4 DLL\u7684\u5378\u8f7d\u4e0e\u8d44\u6e90\u6e05\u7406<\/h4>\n<p>DLL\u7684\u5378\u8f7d\u662f\u52a0\u8f7d\u7684\u9006\u8fc7\u7a0b&#xff0c;\u4f46\u5176\u903b\u8f91\u9700\u8003\u8651\u591a\u8fdb\u7a0b\/\u591a\u7ebf\u7a0b\u5171\u4eab\u7684\u590d\u6742\u6027&#xff1a;<\/p>\n<li>\n<p>\u5f15\u7528\u8ba1\u6570\u673a\u5236&#xff1a;\u6bcf\u4e2aDLL\u6709\u4e00\u4e2a\u5f15\u7528\u8ba1\u6570&#xff0c;LoadLibrary\/\u8fdb\u7a0b\u52a0\u8f7d\u65f6&#043;1&#xff0c;FreeLibrary\/\u8fdb\u7a0b\u9000\u51fa\u65f6-1\u3002\u4ec5\u5f53\u8ba1\u6570\u4e3a0\u65f6&#xff0c;DLL\u624d\u4f1a\u88ab\u771f\u6b63\u5378\u8f7d&#xff08;\u4ece\u5185\u5b58\u4e2d\u79fb\u9664&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u8d44\u6e90\u6e05\u7406\u65f6\u673a&#xff1a;DLL_PROCESS_DETACH\u662f\u6e05\u7406\u8d44\u6e90\u7684\u4e3b\u8981\u65f6\u673a&#xff0c;\u4f46\u9700\u533a\u5206\u4e24\u79cd\u60c5\u51b5&#xff1a;<\/p>\n<ul>\n<li>\u6b63\u5e38\u5378\u8f7d&#xff08;FreeLibrary\u5bfc\u81f4\u8ba1\u6570\u4e3a0&#xff09;&#xff1a;\u9700\u91ca\u653e\u6240\u6709\u5df2\u5206\u914d\u7684\u8d44\u6e90&#xff08;\u5185\u5b58\u3001\u53e5\u67c4\u7b49&#xff09;\u3002<\/li>\n<li>\u8fdb\u7a0b\u9000\u51fa\u65f6\u5378\u8f7d&#xff08;lpvReserved\u4e3a\u975eNULL&#xff09;&#xff1a;\u6b64\u65f6\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u5c06\u88ab\u9500\u6bc1&#xff0c;\u65e0\u9700\u91ca\u653e\u7cfb\u7edf\u8d44\u6e90&#xff08;\u5982\u6587\u4ef6\u53e5\u67c4&#xff0c;\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u56de\u6536&#xff09;&#xff0c;\u907f\u514d\u6e05\u7406\u64cd\u4f5c\u5bfc\u81f4\u5d29\u6e83\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898&#xff1a;\u82e5DLL\u88ab\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u4f7f\u7528&#xff0c;\u5378\u8f7d\u524d\u9700\u786e\u4fdd\u6240\u6709\u7ebf\u7a0b\u5df2\u505c\u6b62\u8c03\u7528DLL\u51fd\u6570&#xff0c;\u5426\u5219\u53ef\u80fd\u5bfc\u81f4\u201c\u60ac\u7a7a\u6307\u9488\u201d&#xff08;\u7ebf\u7a0b\u8c03\u7528\u5df2\u91ca\u653e\u7684\u51fd\u6570\u5730\u5740&#xff09;\u3002<\/p>\n<\/li>\n<p>\u9519\u8bef\u7684\u5378\u8f7d\u903b\u8f91\u662fDLL\u5185\u5b58\u6cc4\u6f0f\u7684\u5e38\u89c1\u539f\u56e0&#xff0c;\u4f8b\u5982&#xff1a;\u672a\u5728DLL_PROCESS_DETACH\u4e2d\u91ca\u653emalloc\u5206\u914d\u7684\u5185\u5b58&#xff0c;\u6216\u91cd\u590d\u8c03\u7528FreeLibrary&#xff08;\u5bfc\u81f4\u5f15\u7528\u8ba1\u6570\u4e3a\u8d1f&#xff09;\u3002<\/p>\n<h3>\u4e94\u3001DLL\u7684\u7c7b\u578b\u4e0e\u5206\u7c7b&#xff1a;\u4ece\u7cfb\u7edf\u5230\u81ea\u5b9a\u4e49<\/h3>\n<p>DLL\u7684\u5e94\u7528\u573a\u666f\u5e7f\u6cdb&#xff0c;\u6309\u529f\u80fd\u3001\u5f00\u53d1\u8bed\u8a00\u3001\u6280\u672f\u7279\u6027\u53ef\u5206\u4e3a\u591a\u79cd\u7c7b\u578b&#xff0c;\u7406\u89e3\u5176\u5206\u7c7b\u6709\u52a9\u4e8e\u9488\u5bf9\u6027\u5730\u4f7f\u7528\u4e0e\u8c03\u8bd5\u3002<\/p>\n<h4>5.1 \u6309\u529f\u80fd\u89d2\u8272\u5206\u7c7b<\/h4>\n<h5>5.1.1 \u7cfb\u7edf\u6838\u5fc3DLL<\/h5>\n<p>\u7cfb\u7edf\u6838\u5fc3DLL\u662fWindows\u64cd\u4f5c\u7cfb\u7edf\u7684\u201c\u9aa8\u67b6\u201d&#xff0c;\u63d0\u4f9b\u5e95\u5c42\u529f\u80fd\u652f\u6301&#xff0c;\u4e3b\u8981\u5b58\u653e\u5728C:\\\\Windows\\\\System32&#xff08;64\u4f4d&#xff09;\u4e0eC:\\\\Windows\\\\SysWOW64&#xff08;32\u4f4d\u517c\u5bb9&#xff09;\u76ee\u5f55&#xff0c;\u5178\u578b\u4ee3\u8868\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>\n<p>kernel32.dll&#xff1a;\u6838\u5fc3\u7cfb\u7edf\u529f\u80fd&#xff0c;\u5982\u8fdb\u7a0b\u7ba1\u7406&#xff08;CreateProcess&#xff09;\u3001\u5185\u5b58\u64cd\u4f5c&#xff08;malloc\/HeapAlloc&#xff09;\u3001\u6587\u4ef6I\/O&#xff08;CreateFile&#xff09;\u3001\u7ebf\u7a0b\u540c\u6b65&#xff08;CreateMutex&#xff09;\u7b49&#xff0c;\u662f\u6240\u6709Windows\u7a0b\u5e8f\u7684\u5fc5\u4f9d\u8d56\u9879\u3002<\/p>\n<\/li>\n<li>\n<p>user32.dll&#xff1a;\u7528\u6237\u754c\u9762\u76f8\u5173\u529f\u80fd&#xff0c;\u5982\u7a97\u53e3\u7ba1\u7406&#xff08;CreateWindow\/DestroyWindow&#xff09;\u3001\u6d88\u606f\u5904\u7406&#xff08;SendMessage&#xff09;\u3001\u83dc\u5355\u4e0e\u5bf9\u8bdd\u6846&#xff08;CreateMenu&#xff09;\u7b49&#xff0c;\u652f\u6491\u56fe\u5f62\u754c\u9762\u5e94\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>gdi32.dll&#xff1a;\u56fe\u5f62\u8bbe\u5907\u63a5\u53e3&#xff08;GDI&#xff09;\u529f\u80fd&#xff0c;\u5982\u7ed8\u56fe&#xff08;LineTo&#xff09;\u3001\u5b57\u4f53\u7ba1\u7406&#xff08;CreateFont&#xff09;\u3001\u4f4d\u56fe\u64cd\u4f5c&#xff08;BitBlt&#xff09;\u7b49&#xff0c;\u8d1f\u8d23\u5c06\u56fe\u5f62\u6570\u636e\u6e32\u67d3\u5230\u5c4f\u5e55\u6216\u6253\u5370\u673a\u3002<\/p>\n<\/li>\n<li>\n<p>advapi32.dll&#xff1a;\u9ad8\u7ea7API&#xff0c;\u5982\u6ce8\u518c\u8868\u64cd\u4f5c&#xff08;RegOpenKey&#xff09;\u3001\u670d\u52a1\u7ba1\u7406&#xff08;StartService&#xff09;\u3001\u5b89\u5168\u8ba4\u8bc1&#xff08;LogonUser&#xff09;\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>msvcrt.dll&#xff1a;C\u6807\u51c6\u5e93DLL&#xff0c;\u63d0\u4f9bprintf\u3001strcpy\u7b49C\u8fd0\u884c\u65f6\u51fd\u6570&#xff0c;\u88abVisual C&#043;&#043;\u7f16\u8bd1\u7684\u7a0b\u5e8f\u4f9d\u8d56\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u4e9bDLL\u7684\u7248\u672c\u4e0eWindows\u7248\u672c\u7ed1\u5b9a&#xff08;\u5982Windows 10\u7684kernel32.dll\u4e0eWindows 11\u7684\u5b9e\u73b0\u4e0d\u540c&#xff09;&#xff0c;\u4fee\u6539\u6216\u66ff\u6362\u53ef\u80fd\u5bfc\u81f4\u7cfb\u7edf\u5d29\u6e83&#xff0c;\u56e0\u6b64\u901a\u5e38\u88ab\u64cd\u4f5c\u7cfb\u7edf\u4fdd\u62a4&#xff08;\u5982\u901a\u8fc7WFP\u6587\u4ef6\u4fdd\u62a4\u673a\u5236&#xff09;\u3002<\/p>\n<h5>5.1.2 \u5e94\u7528\u6846\u67b6DLL<\/h5>\n<p>\u5e94\u7528\u6846\u67b6DLL\u4e3a\u7279\u5b9a\u5f00\u53d1\u6846\u67b6\u63d0\u4f9b\u652f\u6301&#xff0c;\u7b80\u5316\u4e0a\u5c42\u5e94\u7528\u5f00\u53d1&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<ul>\n<li>\n<p>mfc.dll*&#xff1a;MFC&#xff08;Microsoft Foundation Classes&#xff09;\u6846\u67b6DLL&#xff0c;\u63d0\u4f9bC&#043;&#043;\u9762\u5411\u5bf9\u8c61\u7684\u7a97\u53e3\u3001\u63a7\u4ef6\u7b49\u5c01\u88c5&#xff08;\u5982mfc140.dll\u5bf9\u5e94VS2015\u7684MFC&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>atl.dll*&#xff1a;ATL&#xff08;Active Template Library&#xff09;\u6846\u67b6DLL&#xff0c;\u652f\u6301COM\u7ec4\u4ef6\u5f00\u53d1&#xff0c;\u63d0\u4f9b\u8f7b\u91cf\u7ea7\u7684\u7c7b\u6a21\u677f&#xff08;\u5982CComPtr&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>clr.dll&#xff1a;.NET\u516c\u5171\u8bed\u8a00\u8fd0\u884c\u65f6&#xff08;CLR&#xff09;\u6838\u5fc3DLL&#xff0c;\u8d1f\u8d23\u6258\u7ba1\u4ee3\u7801\u7684\u7f16\u8bd1&#xff08;JIT&#xff09;\u3001\u5783\u573e\u56de\u6536\u3001\u5b89\u5168\u68c0\u67e5\u7b49&#xff0c;\u662f\u6240\u6709.NET\u7a0b\u5e8f\u7684\u4f9d\u8d56\u3002<\/p>\n<\/li>\n<li>\n<p>qt.dll*&#xff1a;Qt\u6846\u67b6DLL&#xff0c;\u63d0\u4f9b\u8de8\u5e73\u53f0\u7684\u7a97\u53e3\u3001\u7f51\u7edc\u3001\u6570\u636e\u5e93\u7b49\u529f\u80fd&#xff0c;\u88ab\u57fa\u4e8eQt\u7684\u5e94\u7528&#xff08;\u5982VLC\u64ad\u653e\u5668&#xff09;\u4f9d\u8d56\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>5.1.3 \u81ea\u5b9a\u4e49\u529f\u80fdDLL<\/h5>\n<p>\u81ea\u5b9a\u4e49DLL\u662f\u5f00\u53d1\u8005\u4e3a\u7279\u5b9a\u5e94\u7528\u7f16\u5199\u7684DLL&#xff0c;\u7528\u4e8e\u5c01\u88c5\u4e1a\u52a1\u903b\u8f91&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u529f\u80fd\u6a21\u5757DLL&#xff1a;\u5c06\u8f6f\u4ef6\u6309\u529f\u80fd\u62c6\u5206&#xff0c;\u5982\u89c6\u9891\u7f16\u8f91\u8f6f\u4ef6\u7684video_encoder.dll&#xff08;\u7f16\u7801&#xff09;\u3001audio_filter.dll&#xff08;\u97f3\u9891\u6ee4\u6ce2&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u63d2\u4ef6DLL&#xff1a;\u652f\u6301\u8f6f\u4ef6\u6269\u5c55&#xff0c;\u5982Photoshop\u7684\u6ee4\u955c\u63d2\u4ef6&#xff08;.8bf\u672c\u8d28\u662f\u7279\u6b8aDLL&#xff09;\u3001\u6d4f\u89c8\u5668\u7684\u6269\u5c55\u63d2\u4ef6&#xff08;\u90e8\u5206\u57fa\u4e8eDLL&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u9a71\u52a8\u9002\u914dDLL&#xff1a;\u786c\u4ef6\u5382\u5546\u63d0\u4f9b\u7684DLL&#xff0c;\u7528\u4e8e\u5c01\u88c5\u8bbe\u5907\u9a71\u52a8\u63a5\u53e3&#xff0c;\u4f7f\u5e94\u7528\u7a0b\u5e8f\u65e0\u9700\u76f4\u63a5\u64cd\u4f5c\u5e95\u5c42\u9a71\u52a8&#xff08;\u5982\u6253\u5370\u673aSDK\u4e2d\u7684printer_api.dll&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u81ea\u5b9a\u4e49DLL\u7684\u547d\u540d\u901a\u5e38\u4e0e\u529f\u80fd\u76f8\u5173&#xff08;\u5982payment.dll\u3001encrypt.dll&#xff09;&#xff0c;\u5176\u4f9d\u8d56\u7684\u7cfb\u7edfDLL\u9700\u4e0e\u76ee\u6807\u7cfb\u7edf\u7248\u672c\u5339\u914d&#xff08;\u5982Windows 7\u4e0eWindows 11\u7684kernel32.dll\u5b58\u5728\u5dee\u5f02&#xff09;\u3002<\/p>\n<h4>5.2 \u6309\u5f00\u53d1\u8bed\u8a00\u4e0e\u6280\u672f\u5206\u7c7b<\/h4>\n<h5>5.2.1 \u975e\u6258\u7ba1DLL&#xff08;Native DLL&#xff09;<\/h5>\n<p>\u975e\u6258\u7ba1DLL\u662f\u7528\u539f\u751f\u8bed\u8a00&#xff08;C\u3001C&#043;&#043;\u3001\u6c47\u7f16&#xff09;\u7f16\u5199\u7684DLL&#xff0c;\u7f16\u8bd1\u540e\u76f4\u63a5\u751f\u6210\u673a\u5668\u7801&#xff0c;\u4e0d\u4f9d\u8d56.NET\u7b49\u865a\u62df\u673a&#xff0c;\u53ef\u88ab\u4efb\u4f55\u652f\u6301\u52a8\u6001\u94fe\u63a5\u7684\u8bed\u8a00\u8c03\u7528&#xff08;C\u3001C&#043;&#043;\u3001Python\u3001Java\u7b49&#xff09;\u3002<\/p>\n<p>\u975e\u6258\u7ba1DLL\u7684\u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u76f4\u63a5\u8fd0\u884c\u5728\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u4e4b\u4e0a&#xff0c;\u6027\u80fd\u63a5\u8fd1\u539f\u751f\u4ee3\u7801\u3002<\/li>\n<li>\u5185\u5b58\u7ba1\u7406\u9700\u624b\u52a8\u5904\u7406&#xff08;malloc\/free&#xff09;&#xff0c;\u6613\u56e0\u64cd\u4f5c\u4e0d\u5f53\u5bfc\u81f4\u6cc4\u6f0f\u6216\u5d29\u6e83\u3002<\/li>\n<li>\u5bfc\u51fa\u51fd\u6570\u9700\u663e\u5f0f\u58f0\u660e&#xff08;\u5982C&#043;&#043;\u4e2d\u7528__declspec(dllexport)&#xff09;&#xff0c;\u4e14\u53ef\u80fd\u56e0\u540d\u79f0\u4fee\u9970&#xff08;Name Mangling&#xff09;\u5bfc\u81f4\u8c03\u7528\u56f0\u96be&#xff08;\u9700\u7528extern &#034;C&#034;\u53d6\u6d88\u4fee\u9970&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u793a\u4f8b&#xff08;C&#043;&#043;\u975e\u6258\u7ba1DLL\u5bfc\u51fa\u51fd\u6570&#xff09;&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ MyMath.h<\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">ifdef<\/span> <span class=\"token expression\">MATH_EXPORTS<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name\">MATH_API<\/span> <span class=\"token expression\"><span class=\"token function\">__declspec<\/span><span class=\"token punctuation\">(<\/span>dllexport<span class=\"token punctuation\">)<\/span><\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">else<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name\">MATH_API<\/span> <span class=\"token expression\"><span class=\"token function\">__declspec<\/span><span class=\"token punctuation\">(<\/span>dllimport<span class=\"token punctuation\">)<\/span><\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">endif<\/span><\/span><\/p>\n<p><span class=\"token keyword\">extern<\/span> <span class=\"token string\">&#034;C&#034;<\/span> MATH_API <span class=\"token keyword\">int<\/span> <span class=\"token function\">Add<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> a<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> b<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u7528extern &#034;C&#034;\u907f\u514d\u540d\u79f0\u4fee\u9970<\/span><\/p>\n<p><span class=\"token comment\">\/\/ MyMath.cpp<\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;MyMath.h&#034;<\/span><\/span><br \/>\nMATH_API <span class=\"token keyword\">int<\/span> <span class=\"token function\">Add<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> a<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> b<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> a <span class=\"token operator\">&#043;<\/span> b<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h5>5.2.2 \u6258\u7ba1DLL&#xff08;Managed DLL&#xff09;<\/h5>\n<p>\u6258\u7ba1DLL\u662f\u7528.NET\u8bed\u8a00&#xff08;C#\u3001VB.NET\u3001F#&#xff09;\u7f16\u5199\u7684DLL&#xff0c;\u7f16\u8bd1\u540e\u751f\u6210\u4e2d\u95f4\u8bed\u8a00&#xff08;IL&#xff09;\u4ee3\u7801&#xff0c;\u4f9d\u8d56.NET Framework\/.NET Core\u8fd0\u884c\u65f6&#xff08;CLR&#xff09;&#xff0c;\u9700\u901a\u8fc7CLR\u52a0\u8f7d\u6267\u884c\u3002<\/p>\n<p>\u6258\u7ba1DLL\u7684\u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u5185\u5b58\u7531CLR\u81ea\u52a8\u7ba1\u7406&#xff08;\u5783\u573e\u56de\u6536&#xff09;&#xff0c;\u51cf\u5c11\u5185\u5b58\u6cc4\u6f0f\u98ce\u9669\u3002<\/li>\n<li>\u652f\u6301\u8de8\u8bed\u8a00\u8c03\u7528&#xff08;C#\u53ef\u8c03\u7528VB.NET\u7684DLL&#xff09;&#xff0c;\u56e0\u57fa\u4e8e\u7edf\u4e00\u7684IL\u3002<\/li>\n<li>\u65e0\u6cd5\u76f4\u63a5\u88ab\u975e\u6258\u7ba1\u7a0b\u5e8f\u8c03\u7528&#xff0c;\u9700\u901a\u8fc7\u201c\u5e73\u53f0\u8c03\u7528&#xff08;P\/Invoke&#xff09;\u201d\u6216\u201cCOM\u4e92\u64cd\u4f5c\u201d\u6865\u63a5\u3002<\/li>\n<\/ul>\n<p>\u793a\u4f8b&#xff08;C#\u6258\u7ba1DLL&#xff09;&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ MyMath.cs<\/span><br \/>\n<span class=\"token keyword\">namespace<\/span> <span class=\"token namespace\">MyMath<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Calculator<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">int<\/span><\/span> <span class=\"token function\">Add<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\"><span class=\"token keyword\">int<\/span><\/span> a<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\"><span class=\"token keyword\">int<\/span><\/span> b<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> a <span class=\"token operator\">&#043;<\/span> b<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u7f16\u8bd1\u540e\u751f\u6210MyMath.dll&#xff0c;\u53ef\u88ab\u5176\u4ed6.NET\u7a0b\u5e8f\u76f4\u63a5\u5f15\u7528&#xff08;\u6dfb\u52a0\u9879\u76ee\u5f15\u7528&#xff09;&#xff0c;\u6216\u901a\u8fc7P\/Invoke\u88ab\u975e\u6258\u7ba1\u7a0b\u5e8f\u8c03\u7528&#xff08;\u9700\u5c01\u88c5\u4e3aCOM\u53ef\u89c1\u7c7b\u578b&#xff09;\u3002<\/p>\n<h5>5.2.3 \u6df7\u5408\u6a21\u5f0fDLL&#xff08;Mixed-Mode DLL&#xff09;<\/h5>\n<p>\u6df7\u5408\u6a21\u5f0fDLL\u540c\u65f6\u5305\u542b\u975e\u6258\u7ba1\u4ee3\u7801\u4e0e\u6258\u7ba1\u4ee3\u7801&#xff0c;\u901a\u5e38\u7528\u4e8e\u975e\u6258\u7ba1\u7a0b\u5e8f\u4e0e.NET\u7a0b\u5e8f\u7684\u6865\u63a5&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<ul>\n<li>\u7528C&#043;&#043;\/CLI\u7f16\u5199\u7684DLL&#xff0c;\u65e2\u53ef\u4ee5\u8c03\u7528\u975e\u6258\u7ba1C&#043;&#043;\u4ee3\u7801&#xff0c;\u53c8\u80fd\u66b4\u9732\u6258\u7ba1\u63a5\u53e3\u4f9bC#\u8c03\u7528\u3002<\/li>\n<li>\u5305\u542b\u5c11\u91cf\u6258\u7ba1\u4ee3\u7801&#xff08;\u5982\u8c03\u7528.NET\u52a0\u5bc6\u5e93&#xff09;\u7684\u975e\u6258\u7ba1DLL\u3002<\/li>\n<\/ul>\n<p>\u6df7\u5408\u6a21\u5f0fDLL\u7684\u4f18\u52bf\u662f\u517c\u987e\u6027\u80fd\u4e0e\u5f00\u53d1\u6548\u7387&#xff0c;\u4f46\u590d\u6742\u5ea6\u9ad8&#xff0c;\u4e14\u4f9d\u8d56.NET\u73af\u5883&#xff08;\u5373\u4f7f\u53ea\u6709\u5c11\u91cf\u6258\u7ba1\u4ee3\u7801&#xff09;\u3002<\/p>\n<h4>5.3 \u6309\u8d44\u6e90\u7c7b\u578b\u5206\u7c7b<\/h4>\n<h5>5.3.1 \u4ee3\u7801\u578bDLL<\/h5>\n<p>\u4ee3\u7801\u578bDLL\u4ee5\u5bfc\u51fa\u51fd\u6570\u4e3a\u6838\u5fc3&#xff0c;\u4e3b\u8981\u63d0\u4f9b\u903b\u8f91\u8ba1\u7b97\u3001\u6d41\u7a0b\u63a7\u5236\u7b49\u529f\u80fd&#xff0c;\u5982kernel32.dll&#xff08;\u7cfb\u7edf\u51fd\u6570&#xff09;\u3001crypto.dll&#xff08;\u52a0\u5bc6\u51fd\u6570&#xff09;\u3002<\/p>\n<h5>5.3.2 \u8d44\u6e90\u578bDLL<\/h5>\n<p>\u8d44\u6e90\u578bDLL\u4ee5\u5b58\u50a8\u8d44\u6e90\u4e3a\u4e3b\u8981\u76ee\u7684&#xff0c;\u5305\u542b\u56fe\u6807\u3001\u5b57\u7b26\u4e32\u3001\u5bf9\u8bdd\u6846\u3001\u56fe\u7247\u7b49&#xff0c;\u7528\u4e8e\u8f6f\u4ef6\u7684\u591a\u8bed\u8a00\u9002\u914d\u6216\u8d44\u6e90\u5171\u4eab&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<ul>\n<li>\u591a\u8bed\u8a00\u8f6f\u4ef6\u7684\u8bed\u8a00\u5305DLL&#xff1a;en_us.dll&#xff08;\u82f1\u6587&#xff09;\u3001zh_cn.dll&#xff08;\u7b80\u4f53\u4e2d\u6587&#xff09;&#xff0c;\u5305\u542b\u4e0d\u540c\u8bed\u8a00\u7684\u754c\u9762\u5b57\u7b26\u4e32\u3002<\/li>\n<li>\u5927\u578b\u8f6f\u4ef6\u7684\u8d44\u6e90\u96c6\u5408&#xff1a;\u6e38\u620f\u7684textures.dll&#xff08;\u7eb9\u7406\u8d44\u6e90&#xff09;\u3001sounds.dll&#xff08;\u97f3\u6548\u8d44\u6e90&#xff09;&#xff0c;\u907f\u514d\u4e3b\u7a0b\u5e8f\u4f53\u79ef\u8fc7\u5927\u3002<\/li>\n<\/ul>\n<p>\u8d44\u6e90\u578bDLL\u7684\u5bfc\u51fa\u8868\u901a\u5e38\u4e3a\u7a7a&#xff0c;\u8d44\u6e90\u9700\u901a\u8fc7LoadLibrary&#043;FindResource&#043;LoadResource\u7b49API\u8bfb\u53d6&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ \u4ece\u8d44\u6e90DLL\u52a0\u8f7d\u56fe\u6807<\/span><br \/>\nHMODULE hResDll <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">LoadLibraryA<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;icons.dll&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nHICON hIcon <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">LoadIcon<\/span><span class=\"token punctuation\">(<\/span>hResDll<span class=\"token punctuation\">,<\/span> <span class=\"token function\">MAKEINTRESOURCE<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">101<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u52a0\u8f7dID\u4e3a101\u7684\u56fe\u6807<\/span><\/p>\n<h3>\u516d\u3001DLL\u7684\u521b\u5efa\u4e0e\u8c03\u7528\u5b9e\u8df5&#xff1a;\u4ece\u4ee3\u7801\u5230\u6267\u884c<\/h3>\n<p>\u638c\u63e1DLL\u7684\u521b\u5efa\u4e0e\u8c03\u7528\u662f\u5f00\u53d1\u8005\u7684\u6838\u5fc3\u6280\u80fd&#xff0c;\u672c\u8282\u4ee5Visual Studio\u4e3a\u5de5\u5177&#xff0c;\u8be6\u7ec6\u8bb2\u89e3\u975e\u6258\u7ba1DLL\u4e0e\u6258\u7ba1DLL\u7684\u5f00\u53d1\u6d41\u7a0b\u3002<\/p>\n<h4>6.1 \u975e\u6258\u7ba1DLL\u7684\u521b\u5efa\u4e0e\u8c03\u7528&#xff08;C&#043;&#043;&#xff09;<\/h4>\n<h5>6.1.1 \u521b\u5efa\u975e\u6258\u7ba1DLL<\/h5>\n<p>\u6b65\u9aa41&#xff1a;\u65b0\u5efa\u9879\u76ee \u6253\u5f00Visual Studio \u2192 \u521b\u5efa\u65b0\u9879\u76ee \u2192 \u9009\u62e9\u201c\u52a8\u6001\u94fe\u63a5\u5e93&#xff08;DLL&#xff09;\u201d \u2192 \u547d\u540d\u4e3a\u201cMathLibrary\u201d \u2192 \u786e\u5b9a\u3002<\/p>\n<p>\u6b65\u9aa42&#xff1a;\u7f16\u5199\u5bfc\u51fa\u51fd\u6570 \u9879\u76ee\u81ea\u52a8\u751f\u6210pch.h\u4e0epch.cpp&#xff0c;\u4fee\u6539\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ pch.h<\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">ifndef<\/span> <span class=\"token expression\">PCH_H<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name\">PCH_H<\/span><\/span><\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;framework.h&#034;<\/span><\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u5b9a\u4e49\u5bfc\u51fa\u5b8f&#xff08;\u9879\u76ee\u5c5e\u6027\u4e2d\u5df2\u5b9a\u4e49MATHLIBRARY_EXPORTS&#xff09;<\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">ifdef<\/span> <span class=\"token expression\">MATHLIBRARY_EXPORTS<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name\">MATHLIBRARY_API<\/span> <span class=\"token expression\"><span class=\"token function\">__declspec<\/span><span class=\"token punctuation\">(<\/span>dllexport<span class=\"token punctuation\">)<\/span><\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">else<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name\">MATHLIBRARY_API<\/span> <span class=\"token expression\"><span class=\"token function\">__declspec<\/span><span class=\"token punctuation\">(<\/span>dllimport<span class=\"token punctuation\">)<\/span><\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">endif<\/span><\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u5bfc\u51fa\u51fd\u6570\u58f0\u660e&#xff08;\u7528extern &#034;C&#034;\u907f\u514dC&#043;&#043;\u540d\u79f0\u4fee\u9970&#xff09;<\/span><br \/>\n<span class=\"token keyword\">extern<\/span> <span class=\"token string\">&#034;C&#034;<\/span> MATHLIBRARY_API <span class=\"token keyword\">int<\/span> <span class=\"token function\">Add<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> a<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> b<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">extern<\/span> <span class=\"token string\">&#034;C&#034;<\/span> MATHLIBRARY_API <span class=\"token keyword\">int<\/span> <span class=\"token function\">Multiply<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> a<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> b<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">endif<\/span> <span class=\"token comment\">\/\/ PCH_H<\/span><\/span><\/p>\n<p><span class=\"token comment\">\/\/ pch.cpp<\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;pch.h&#034;<\/span><\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u51fd\u6570\u5b9e\u73b0<\/span><br \/>\nMATHLIBRARY_API <span class=\"token keyword\">int<\/span> <span class=\"token function\">Add<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> a<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> b<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> a <span class=\"token operator\">&#043;<\/span> b<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>MATHLIBRARY_API <span class=\"token keyword\">int<\/span> <span class=\"token function\">Multiply<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> a<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> b<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> a <span class=\"token operator\">*<\/span> b<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6b65\u9aa43&#xff1a;\u7f16\u8bd1\u751f\u6210DLL \u70b9\u51fb\u201c\u751f\u6210\u201d\u2192\u201c\u751f\u6210\u89e3\u51b3\u65b9\u6848\u201d&#xff0c;\u6210\u529f\u540e\u5728x64\\\\Debug\u76ee\u5f55\u4e0b\u751f\u6210MathLibrary.dll&#xff08;DLL\u6587\u4ef6&#xff09;\u3001MathLibrary.lib&#xff08;\u5bfc\u5165\u5e93&#xff09;\u3001MathLibrary.pdb&#xff08;\u8c03\u8bd5\u4fe1\u606f&#xff09;\u3002<\/p>\n<h5>6.1.2 \u9759\u6001\u8c03\u7528\u975e\u6258\u7ba1DLL&#xff08;C&#043;&#043;&#xff09;<\/h5>\n<p>\u6b65\u9aa41&#xff1a;\u65b0\u5efa\u63a7\u5236\u53f0\u9879\u76ee \u521b\u5efa\u201c\u63a7\u5236\u53f0\u5e94\u7528\u201d\u9879\u76ee\u201cMathClient\u201d&#xff0c;\u7528\u4e8e\u8c03\u7528DLL\u3002<\/p>\n<p>\u6b65\u9aa42&#xff1a;\u914d\u7f6e\u4f9d\u8d56<\/p>\n<ul>\n<li>\u5c06MathLibrary.h\u590d\u5236\u5230MathClient\u9879\u76ee\u76ee\u5f55&#xff08;\u6216\u6dfb\u52a0\u5305\u542b\u76ee\u5f55&#xff09;\u3002<\/li>\n<li>\u5c06MathLibrary.lib\u590d\u5236\u5230MathClient\u7684\u8f93\u51fa\u76ee\u5f55&#xff08;\u6216\u5728\u9879\u76ee\u5c5e\u6027\u2192\u201c\u94fe\u63a5\u5668\u201d\u2192\u201c\u8f93\u5165\u201d\u2192\u201c\u9644\u52a0\u4f9d\u8d56\u9879\u201d\u4e2d\u6dfb\u52a0\u8def\u5f84&#xff09;\u3002<\/li>\n<li>\u5c06MathLibrary.dll\u590d\u5236\u5230MathClient\u7684\u8f93\u51fa\u76ee\u5f55&#xff08;\u4e0eMathClient.exe\u540c\u76ee\u5f55&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u6b65\u9aa43&#xff1a;\u7f16\u5199\u8c03\u7528\u4ee3\u7801<\/p>\n<p><span class=\"token comment\">\/\/ MathClient.cpp<\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;iostream&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;MathLibrary.h&#034;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> a <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> b <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;Add: &#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">Add<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">,<\/span> b<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;&lt;<\/span> std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ \u8f93\u51fa5<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;Multiply: &#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">Multiply<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">,<\/span> b<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;&lt;<\/span> std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u8f93\u51fa6<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6b65\u9aa44&#xff1a;\u8fd0\u884c\u7a0b\u5e8f \u7f16\u8bd1\u5e76\u8fd0\u884cMathClient.exe&#xff0c;\u6210\u529f\u8f93\u51fa\u8ba1\u7b97\u7ed3\u679c&#xff0c;\u8bf4\u660e\u9759\u6001\u8c03\u7528\u751f\u6548\u3002<\/p>\n<h5>6.1.3 \u52a8\u6001\u8c03\u7528\u975e\u6258\u7ba1DLL&#xff08;C&#043;&#043;&#xff09;<\/h5>\n<p>\u65e0\u9700\u4f9d\u8d56MathLibrary.lib&#xff0c;\u76f4\u63a5\u901a\u8fc7API\u52a0\u8f7dDLL&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ MathClient.cpp<\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;iostream&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;windows.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u52a0\u8f7dDLL<\/span><br \/>\n    HMODULE hDll <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">LoadLibraryA<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;MathLibrary.dll&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span>hDll<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;Load failed: &#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">GetLastError<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;&lt;<\/span> std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u83b7\u53d6\u51fd\u6570\u5730\u5740<\/span><br \/>\n    <span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">int<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span>AddFunc<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">int<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span>MultiplyFunc<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    AddFunc add <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span>AddFunc<span class=\"token punctuation\">)<\/span><span class=\"token function\">GetProcAddress<\/span><span class=\"token punctuation\">(<\/span>hDll<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;Add&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    MultiplyFunc multiply <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span>MultiplyFunc<span class=\"token punctuation\">)<\/span><span class=\"token function\">GetProcAddress<\/span><span class=\"token punctuation\">(<\/span>hDll<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;Multiply&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span>add <span class=\"token operator\">||<\/span> <span class=\"token operator\">!<\/span>multiply<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;Get function failed: &#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">GetLastError<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;&lt;<\/span> std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token function\">FreeLibrary<\/span><span class=\"token punctuation\">(<\/span>hDll<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u8c03\u7528\u51fd\u6570<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> a <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> b <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;Add: &#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">add<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">,<\/span> b<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;&lt;<\/span> std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;Multiply: &#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">multiply<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">,<\/span> b<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;&lt;<\/span> std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u5378\u8f7dDLL<\/span><br \/>\n    <span class=\"token function\">FreeLibrary<\/span><span class=\"token punctuation\">(<\/span>hDll<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u52a8\u6001\u8c03\u7528\u7684\u5173\u952e\u662f\u786e\u4fdd\u51fd\u6570\u6307\u9488\u7c7b\u578b\u4e0eDLL\u5bfc\u51fa\u51fd\u6570\u4e00\u81f4&#xff08;\u53c2\u6570\u4e2a\u6570\u3001\u7c7b\u578b\u3001\u8fd4\u56de\u503c&#xff09;&#xff0c;\u5426\u5219\u4f1a\u5bfc\u81f4\u6808\u6ea2\u51fa\u6216\u6570\u636e\u9519\u8bef\u3002<\/p>\n<h4>6.2 \u6258\u7ba1DLL\u7684\u521b\u5efa\u4e0e\u8c03\u7528&#xff08;C#&#xff09;<\/h4>\n<h5>6.2.1 \u521b\u5efa\u6258\u7ba1DLL&#xff08;C#&#xff09;<\/h5>\n<p>\u6b65\u9aa41&#xff1a;\u65b0\u5efa\u9879\u76ee Visual Studio \u2192 \u521b\u5efa\u65b0\u9879\u76ee \u2192 \u9009\u62e9\u201c\u7c7b\u5e93&#xff08;.NET Framework&#xff09;\u201d \u2192 \u547d\u540d\u4e3a\u201cCSharpLibrary\u201d \u2192 \u9009\u62e9.NET Framework\u7248\u672c&#xff08;\u59824.7.2&#xff09;\u3002<\/p>\n<p>\u6b65\u9aa42&#xff1a;\u7f16\u5199\u7c7b\u4e0e\u65b9\u6cd5<\/p>\n<p><span class=\"token comment\">\/\/ MathOperations.cs<\/span><br \/>\n<span class=\"token keyword\">namespace<\/span> <span class=\"token namespace\">CSharpLibrary<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">MathOperations<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u516c\u5171\u65b9\u6cd5\u81ea\u52a8\u5bfc\u51fa&#xff08;\u6258\u7ba1DLL\u65e0\u9700\u663e\u5f0f\u58f0\u660e\u5bfc\u51fa&#xff09;<\/span><br \/>\n        <span class=\"token keyword\">public<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">int<\/span><\/span> <span class=\"token function\">Subtract<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\"><span class=\"token keyword\">int<\/span><\/span> a<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\"><span class=\"token keyword\">int<\/span><\/span> b<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> a <span class=\"token operator\">&#8211;<\/span> b<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><\/p>\n<p>        <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">double<\/span><\/span> <span class=\"token function\">Divide<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\"><span class=\"token keyword\">double<\/span><\/span> a<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\"><span class=\"token keyword\">double<\/span><\/span> b<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>b <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">throw<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token constructor-invocation class-name\">DivideByZeroException<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> a <span class=\"token operator\">\/<\/span> b<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6b65\u9aa43&#xff1a;\u751f\u6210DLL \u70b9\u51fb\u201c\u751f\u6210\u201d\u2192\u201c\u751f\u6210\u89e3\u51b3\u65b9\u6848\u201d&#xff0c;\u5728bin\\\\Debug\u76ee\u5f55\u751f\u6210CSharpLibrary.dll&#xff08;\u6258\u7ba1DLL&#xff09;\u3002<\/p>\n<h5>6.2.2 \u8c03\u7528\u6258\u7ba1DLL&#xff08;C#&#xff09;<\/h5>\n<p>\u6b65\u9aa41&#xff1a;\u6dfb\u52a0\u5f15\u7528 \u65b0\u5efaC#\u63a7\u5236\u53f0\u9879\u76ee\u201cCSharpClient\u201d \u2192 \u53f3\u952e\u201c\u5f15\u7528\u201d\u2192\u201c\u6dfb\u52a0\u5f15\u7528\u201d\u2192\u201c\u6d4f\u89c8\u201d\u2192 \u9009\u62e9CSharpLibrary.dll\u3002<\/p>\n<p>\u6b65\u9aa42&#xff1a;\u7f16\u5199\u8c03\u7528\u4ee3\u7801<\/p>\n<p><span class=\"token keyword\">using<\/span> <span class=\"token namespace\">System<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">using<\/span> <span class=\"token namespace\">CSharpLibrary<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">namespace<\/span> <span class=\"token namespace\">CSharpClient<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Program<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">static<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">void<\/span><\/span> <span class=\"token function\">Main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\"><span class=\"token keyword\">string<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><\/span> args<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token class-name\">MathOperations<\/span> math <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token constructor-invocation class-name\">MathOperations<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            Console<span class=\"token punctuation\">.<\/span><span class=\"token function\">WriteLine<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Subtract: &#034;<\/span> <span class=\"token operator\">&#043;<\/span> math<span class=\"token punctuation\">.<\/span><span class=\"token function\">Subtract<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u8f93\u51fa2<\/span><\/p>\n<p>            <span class=\"token class-name\"><span class=\"token keyword\">double<\/span><\/span> divResult <span class=\"token operator\">&#061;<\/span> MathOperations<span class=\"token punctuation\">.<\/span><span class=\"token function\">Divide<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">6<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            Console<span class=\"token punctuation\">.<\/span><span class=\"token function\">WriteLine<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Divide: &#034;<\/span> <span class=\"token operator\">&#043;<\/span> divResult<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u8f93\u51fa3<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6b65\u9aa43&#xff1a;\u8fd0\u884c\u7a0b\u5e8f \u6258\u7ba1DLL\u7684\u8c03\u7528\u65e0\u9700\u590d\u5236DLL\u5230\u8f93\u51fa\u76ee\u5f55&#xff08;\u5f15\u7528\u4f1a\u81ea\u52a8\u590d\u5236&#xff09;&#xff0c;\u8fd0\u884c\u540e\u6210\u529f\u8f93\u51fa\u7ed3\u679c\u3002<\/p>\n<h5>6.2.3 \u975e\u6258\u7ba1\u7a0b\u5e8f\u8c03\u7528\u6258\u7ba1DLL&#xff08;C&#043;&#043;\u8c03\u7528C# DLL&#xff09;<\/h5>\n<p>\u975e\u6258\u7ba1\u7a0b\u5e8f&#xff08;\u5982C&#043;&#043;&#xff09;\u8c03\u7528\u6258\u7ba1DLL\u9700\u901a\u8fc7\u201cCOM\u4e92\u64cd\u4f5c\u201d\u6216\u201cCLR\u5bbf\u4e3b\u201d&#xff0c;\u4ee5\u4e0b\u662f\u57fa\u4e8eCOM\u4e92\u64cd\u4f5c\u7684\u6d41\u7a0b&#xff1a;<\/p>\n<p>\u6b65\u9aa41&#xff1a;\u914d\u7f6e\u6258\u7ba1DLL\u4e3aCOM\u53ef\u89c1 \u5728CSharpLibrary\u9879\u76ee\u7684AssemblyInfo.cs\u4e2d\u8bbe\u7f6e&#xff1a;<\/p>\n<p><span class=\"token punctuation\">[<\/span><span class=\"token attribute\"><span class=\"token target keyword\">assembly<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token class-name\">ComVisible<\/span><span class=\"token attribute-arguments\"><span class=\"token punctuation\">(<\/span><span class=\"token boolean\">true<\/span><span class=\"token punctuation\">)<\/span><\/span><\/span><span class=\"token punctuation\">]<\/span>  <span class=\"token comment\">\/\/ \u5141\u8bb8COM\u8bbf\u95ee<\/span><br \/>\n<span class=\"token punctuation\">[<\/span><span class=\"token attribute\"><span class=\"token target keyword\">assembly<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token class-name\">Guid<\/span><span class=\"token attribute-arguments\"><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Your-GUID-Here&#034;<\/span><span class=\"token punctuation\">)<\/span><\/span><\/span><span class=\"token punctuation\">]<\/span>  <span class=\"token comment\">\/\/ \u751f\u6210\u552f\u4e00GUID&#xff08;\u5de5\u5177\u2192\u521b\u5efaGUID&#xff09;<\/span><\/p>\n<p>\u6b65\u9aa42&#xff1a;\u6ce8\u518cCOM\u7ec4\u4ef6 \u751f\u6210DLL\u540e&#xff0c;\u901a\u8fc7regasm.exe\u6ce8\u518c&#xff08;\u9700\u7ba1\u7406\u5458\u6743\u9650&#xff09;&#xff1a;<\/p>\n<p>regasm.exe C:\\\\path\\\\to\\\\CSharpLibrary.dll \/tlb:CSharpLibrary.tlb<\/p>\n<p>\u6b65\u9aa43&#xff1a;C&#043;&#043;\u4e2d\u901a\u8fc7COM\u8c03\u7528<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;iostream&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;windows.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;CSharpLibrary.tlb&#034;<\/span>  <span class=\"token comment\">\/\/ \u5bfc\u5165\u7c7b\u578b\u5e93<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u521d\u59cb\u5316COM<\/span><br \/>\n    <span class=\"token function\">CoInitialize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u521b\u5efa\u6258\u7ba1DLL\u7684COM\u5bf9\u8c61<\/span><br \/>\n    CSharpLibrary<span class=\"token operator\">::<\/span>IMathOperationsPtr pMath<span class=\"token punctuation\">;<\/span><br \/>\n    HRESULT hr <span class=\"token operator\">&#061;<\/span> pMath<span class=\"token punctuation\">.<\/span><span class=\"token function\">CreateInstance<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">__uuidof<\/span><span class=\"token punctuation\">(<\/span>CSharpLibrary<span class=\"token operator\">::<\/span>MathOperations<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">SUCCEEDED<\/span><span class=\"token punctuation\">(<\/span>hr<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;Subtract: &#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> pMath<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">Subtract<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;&lt;<\/span> std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u8f93\u51fa2<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u91ca\u653eCOM<\/span><br \/>\n    <span class=\"token function\">CoUninitialize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6258\u7ba1DLL\u7684COM\u4e92\u64cd\u4f5c\u9700\u6ce8\u610f\u7c7b\u578b\u5339\u914d&#xff08;\u5982C#\u7684int\u5bf9\u5e94COM\u7684long&#xff09;&#xff0c;\u4e14\u9700\u786e\u4fdd\u76ee\u6807\u7cfb\u7edf\u5b89\u88c5\u4e86\u5bf9\u5e94\u7248\u672c\u7684.NET Framework\u3002<\/p>\n<h4>6.3 \u8de8\u8bed\u8a00\u8c03\u7528DLL&#xff08;Python\u8c03\u7528C&#043;&#043; DLL&#xff09;<\/h4>\n<p>Python\u53ef\u901a\u8fc7ctypes\u5e93\u8c03\u7528\u975e\u6258\u7ba1DLL&#xff0c;\u793a\u4f8b\u5982\u4e0b&#xff1a;<\/p>\n<p>\u6b65\u9aa41&#xff1a;\u51c6\u5907C&#043;&#043; DLL&#xff08;\u5bfc\u51fa\u51fd\u6570&#xff09;<\/p>\n<p><span class=\"token comment\">\/\/ \u5bfc\u51fa\u51fd\u6570&#xff08;\u9700\u7528extern &#034;C&#034;&#xff09;<\/span><br \/>\n<span class=\"token keyword\">extern<\/span> <span class=\"token string\">&#034;C&#034;<\/span> <span class=\"token function\">__declspec<\/span><span class=\"token punctuation\">(<\/span>dllexport<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">int<\/span> <span class=\"token function\">Power<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> base<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> exponent<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> result <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> exponent<span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> result <span class=\"token operator\">*&#061;<\/span> base<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> result<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6b65\u9aa42&#xff1a;Python\u8c03\u7528\u4ee3\u7801<\/p>\n<p><span class=\"token keyword\">import<\/span> ctypes<\/p>\n<p><span class=\"token comment\"># \u52a0\u8f7dDLL<\/span><br \/>\ndll <span class=\"token operator\">&#061;<\/span> ctypes<span class=\"token punctuation\">.<\/span>CDLL<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;MathLibrary.dll&#034;<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u82e5\u5728\u5176\u4ed6\u8def\u5f84\u9700\u6307\u5b9a\u5b8c\u6574\u8def\u5f84<\/span><\/p>\n<p><span class=\"token comment\"># \u58f0\u660e\u51fd\u6570\u53c2\u6570\u4e0e\u8fd4\u56de\u503c\u7c7b\u578b&#xff08;\u786e\u4fdd\u5339\u914d&#xff09;<\/span><br \/>\ndll<span class=\"token punctuation\">.<\/span>Power<span class=\"token punctuation\">.<\/span>argtypes <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span>ctypes<span class=\"token punctuation\">.<\/span>c_int<span class=\"token punctuation\">,<\/span> ctypes<span class=\"token punctuation\">.<\/span>c_int<span class=\"token punctuation\">]<\/span><br \/>\ndll<span class=\"token punctuation\">.<\/span>Power<span class=\"token punctuation\">.<\/span>restype <span class=\"token operator\">&#061;<\/span> ctypes<span class=\"token punctuation\">.<\/span>c_int<\/p>\n<p><span class=\"token comment\"># \u8c03\u7528\u51fd\u6570<\/span><br \/>\nresult <span class=\"token operator\">&#061;<\/span> dll<span class=\"token punctuation\">.<\/span>Power<span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># 2^3&#061;8<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Power result:&#034;<\/span><span class=\"token punctuation\">,<\/span> result<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u8f93\u51fa8<\/span><\/p>\n<p>ctypes\u4f1a\u81ea\u52a8\u5904\u7406\u53c2\u6570\u7684\u7c7b\u578b\u8f6c\u6362&#xff08;\u5982Python\u7684int\u8f6cC\u7684int&#xff09;&#xff0c;\u4f46\u590d\u6742\u7c7b\u578b&#xff08;\u5982\u7ed3\u6784\u4f53\u3001\u6307\u9488&#xff09;\u9700\u663e\u5f0f\u5b9a\u4e49\u7c7b\u578b\u6620\u5c04\u3002<\/p>\n<h3>\u4e03\u3001DLL\u7684\u4f9d\u8d56\u7ba1\u7406\u4e0e\u201c\u4f9d\u8d56\u5730\u72f1\u201d<\/h3>\n<p>DLL\u7684\u4f9d\u8d56\u5173\u7cfb\u662f\u5176\u7075\u6d3b\u6027\u7684\u53cc\u5203\u5251&#xff1a;\u4e00\u65b9\u9762&#xff0c;\u591a\u5c42\u4f9d\u8d56\u5b9e\u73b0\u4e86\u529f\u80fd\u590d\u7528&#xff1b;\u53e6\u4e00\u65b9\u9762&#xff0c;\u4f9d\u8d56\u7f3a\u5931\u6216\u7248\u672c\u51b2\u7a81\u4f1a\u5bfc\u81f4\u201c\u4f9d\u8d56\u5730\u72f1&#xff08;DLL Hell&#xff09;\u201d\u2014\u2014\u8fd9\u662fWindows\u5f00\u53d1\u4e2d\u6700\u5e38\u89c1\u7684\u95ee\u9898\u4e4b\u4e00\u3002<\/p>\n<h4>7.1 DLL\u7684\u4f9d\u8d56\u94fe\u4e0e\u67e5\u770b\u5de5\u5177<\/h4>\n<h5>7.1.1 \u4f9d\u8d56\u94fe\u7684\u5f62\u6210<\/h5>\n<p>\u4e00\u4e2aDLL\u53ef\u80fd\u4f9d\u8d56\u5176\u4ed6DLL&#xff0c;\u5f62\u6210\u201c\u4f9d\u8d56\u94fe\u201d\u3002\u4f8b\u5982&#xff0c;user32.dll\u4f9d\u8d56gdi32.dll&#xff0c;gdi32.dll\u4f9d\u8d56kernel32.dll&#xff0c;\u800c\u4f60\u7684\u7a0b\u5e8f\u4f9d\u8d56user32.dll&#xff0c;\u5219\u5b8c\u6574\u4f9d\u8d56\u94fe\u4e3a&#xff1a;\u4f60\u7684\u7a0b\u5e8f \u2192 user32.dll \u2192 gdi32.dll \u2192 kernel32.dll\u3002<\/p>\n<p>\u4f9d\u8d56\u94fe\u7684\u6df1\u5ea6\u53ef\u80fd\u8fbe\u591a\u5c42&#xff08;\u5982\u67d0\u4e9b\u590d\u6742\u8f6f\u4ef6\u7684\u4f9d\u8d56\u94fe\u8d85\u8fc710\u5c42&#xff09;&#xff0c;\u4efb\u4f55\u4e00\u5c42\u7684DLL\u7f3a\u5931\u6216\u4e0d\u517c\u5bb9\u90fd\u4f1a\u5bfc\u81f4\u6574\u4e2a\u7a0b\u5e8f\u5931\u8d25\u3002<\/p>\n<h5>7.1.2 \u67e5\u770b\u4f9d\u8d56\u7684\u5de5\u5177<\/h5>\n<p>\u5206\u6790DLL\u4f9d\u8d56\u7684\u5e38\u7528\u5de5\u5177&#xff1a;<\/p>\n<li>\n<p>Dependency Walker&#xff08;depends.exe&#xff09;&#xff1a;\u7ecf\u5178\u5de5\u5177&#xff0c;\u53ef\u663e\u793aDLL\u7684\u5b8c\u6574\u4f9d\u8d56\u94fe&#xff0c;\u6807\u8bb0\u7f3a\u5931\u7684\u4f9d\u8d56\u9879\u3002\u4f46\u5bf964\u4f4dDLL\u652f\u6301\u6709\u9650&#xff0c;\u4e14\u65e0\u6cd5\u8bc6\u522b.NET\u6258\u7ba1DLL\u7684\u4f9d\u8d56\u3002<\/p>\n<\/li>\n<li>\n<p>Process Explorer&#xff1a;\u5fae\u8f6fSysinternals\u5de5\u5177&#xff0c;\u53ef\u67e5\u770b\u8fd0\u884c\u4e2d\u8fdb\u7a0b\u52a0\u8f7d\u7684\u6240\u6709DLL&#xff08;\u53cc\u51fb\u8fdb\u7a0b\u2192\u201cDLL\u201d\u6807\u7b7e&#xff09;&#xff0c;\u5305\u62ec\u8def\u5f84\u3001\u7248\u672c\u3001\u516c\u53f8\u4fe1\u606f&#xff0c;\u4fbf\u4e8e\u5b9a\u4f4d\u51b2\u7a81\u7684DLL&#xff08;\u5982\u540c\u4e00DLL\u7684\u4e0d\u540c\u7248\u672c&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>dumpbin.exe&#xff1a;Visual Studio\u81ea\u5e26\u5de5\u5177&#xff0c;\u901a\u8fc7\u547d\u4ee4dumpbin \/dependents MyDll.dll\u67e5\u770bDLL\u7684\u76f4\u63a5\u4f9d\u8d56&#xff08;\u4e0d\u5305\u542b\u95f4\u63a5\u4f9d\u8d56&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>ILSpy&#xff1a;\u67e5\u770b\u6258\u7ba1DLL\u7684\u4f9d\u8d56&#xff08;.NET\u7a0b\u5e8f\u96c6&#xff09;&#xff0c;\u652f\u6301\u53cd\u7f16\u8bd1\u6258\u7ba1\u4ee3\u7801&#xff0c;\u5206\u6790\u4f9d\u8d56\u7684.NET\u5e93\u3002<\/p>\n<\/li>\n<h4>7.2 \u201c\u4f9d\u8d56\u5730\u72f1\u201d\u7684\u8868\u73b0\u4e0e\u6210\u56e0<\/h4>\n<h5>7.2.1 \u4f9d\u8d56\u5730\u72f1\u7684\u5178\u578b\u8868\u73b0<\/h5>\n<li>\n<p>\u201c\u627e\u4e0d\u5230xxx.dll\u201d\u9519\u8bef&#xff1a;\u7a0b\u5e8f\u542f\u52a8\u65f6\u5f39\u51fa\u5bf9\u8bdd\u6846&#xff0c;\u63d0\u793a\u7f3a\u5931\u67d0\u4e2aDLL&#xff08;\u5982msvcp140.dll&#xff09;&#xff0c;\u901a\u5e38\u662f\u56e0\u4e3a\u4f9d\u8d56\u7684DLL\u672a\u5b89\u88c5\u6216\u4e0d\u5728\u641c\u7d22\u8def\u5f84\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>\u201c\u5e94\u7528\u7a0b\u5e8f\u65e0\u6cd5\u542f\u52a8&#xff0c;\u56e0\u4e3a\u5e94\u7528\u7a0b\u5e8f\u7684\u5e76\u884c\u914d\u7f6e\u4e0d\u6b63\u786e\u201d&#xff1a;\u56e0DLL\u7248\u672c\u4e0d\u517c\u5bb9&#xff08;\u5982\u7a0b\u5e8f\u9700\u8981msvcr120.dll&#xff0c;\u4f46\u7cfb\u7edf\u4e2d\u53ea\u6709msvcr140.dll&#xff09;\u6216 manifests\u6587\u4ef6\u914d\u7f6e\u9519\u8bef\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fd0\u884c\u65f6\u5d29\u6e83&#xff08;0xC0000005\u8bbf\u95ee\u51b2\u7a81&#xff09;&#xff1a;DLL\u7248\u672c\u4e0d\u5339\u914d\u5bfc\u81f4\u51fd\u6570\u7b7e\u540d\u53d8\u5316&#xff08;\u5982\u53c2\u6570\u4e2a\u6570\u589e\u52a0&#xff09;&#xff0c;\u8c03\u7528\u65f6\u4f20\u9012\u7684\u53c2\u6570\u4e0eDLL\u671f\u671b\u7684\u4e0d\u4e00\u81f4&#xff0c;\u5bfc\u81f4\u5185\u5b58\u8bbf\u95ee\u9519\u8bef\u3002<\/p>\n<\/li>\n<li>\n<p>\u529f\u80fd\u5f02\u5e38&#xff1a;DLL\u7248\u672c\u4e0d\u540c\u5bfc\u81f4\u884c\u4e3a\u5dee\u5f02&#xff0c;\u4f8b\u5982\u65e7\u7248\u672ccrypto.dll\u4e0d\u652f\u6301\u65b0\u52a0\u5bc6\u7b97\u6cd5&#xff0c;\u5bfc\u81f4\u7a0b\u5e8f\u52a0\u5bc6\u529f\u80fd\u5931\u6548\u3002<\/p>\n<\/li>\n<h5>7.2.2 \u4f9d\u8d56\u5730\u72f1\u7684\u6210\u56e0<\/h5>\n<li>\n<p>\u7248\u672c\u4e0d\u517c\u5bb9&#xff1a;DLL\u7684\u65b0\u7248\u672c\u4fee\u6539\u4e86\u5bfc\u51fa\u51fd\u6570&#xff08;\u53c2\u6570\u3001\u8fd4\u56de\u503c\u53d8\u5316&#xff09;&#xff0c;\u4f46\u672a\u66f4\u65b0\u7248\u672c\u53f7&#xff0c;\u5bfc\u81f4\u4f9d\u8d56\u65e7\u7248\u672c\u7684\u7a0b\u5e8f\u8c03\u7528\u5931\u8d25\u3002\u4f8b\u5982&#xff0c;v1.0\u7684Add\u51fd\u6570\u4e3aint Add(int a, int b)&#xff0c;v2.0\u6539\u4e3aint Add(int a, int b, int c)&#xff0c;\u65e7\u7a0b\u5e8f\u8c03\u7528\u65f6\u4f1a\u5c11\u4f20\u4e00\u4e2a\u53c2\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>\u540c\u540dDLL\u51b2\u7a81&#xff1a;\u4e0d\u540c\u5382\u5546\u7684DLL\u91cd\u540d&#xff08;\u5982util.dll&#xff09;&#xff0c;\u4e14\u90fd\u5728\u641c\u7d22\u8def\u5f84\u4e2d&#xff0c;\u7a0b\u5e8f\u52a0\u8f7d\u4e86\u9519\u8bef\u7684DLL&#xff08;\u4f8b\u5982\u9884\u671f\u52a0\u8f7dC:\\\\ProgramA\\\\util.dll&#xff0c;\u5374\u52a0\u8f7d\u4e86C:\\\\ProgramB\\\\util.dll&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u7cfb\u7edfDLL\u66ff\u6362&#xff1a;\u7528\u6237\u6216\u6076\u610f\u8f6f\u4ef6\u66ff\u6362\u4e86\u7cfb\u7edfDLL&#xff08;\u5982kernel32.dll&#xff09;&#xff0c;\u5bfc\u81f4\u4f9d\u8d56\u7cfb\u7edfDLL\u7684\u7a0b\u5e8f\u5168\u90e8\u5d29\u6e83&#xff08;Windows\u901a\u8fc7WFP\u6587\u4ef6\u4fdd\u62a4\u673a\u5236\u7f13\u89e3\u6b64\u95ee\u9898&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b89\u88c5\/\u5378\u8f7d\u6b8b\u7559&#xff1a;\u8f6f\u4ef6\u5378\u8f7d\u65f6\u672a\u6e05\u7406\u5176\u5b89\u88c5\u7684DLL&#xff0c;\u5bfc\u81f4\u5176\u4ed6\u4f9d\u8d56\u8be5DLL\u7684\u7a0b\u5e8f\u5728DLL\u88ab\u5220\u9664\u540e\u5931\u8d25\u3002<\/p>\n<\/li>\n<h4>7.3 \u89e3\u51b3\u4f9d\u8d56\u5730\u72f1\u7684\u6280\u672f\u65b9\u6848<\/h4>\n<h5>7.3.1 \u5e94\u7528\u7a0b\u5e8f\u672c\u5730\u90e8\u7f72&#xff08;Private DLLs&#xff09;<\/h5>\n<p>\u5c06\u7a0b\u5e8f\u4f9d\u8d56\u7684\u6240\u6709DLL\u590d\u5236\u5230\u7a0b\u5e8f\u7684\u5b89\u88c5\u76ee\u5f55&#xff08;\u4e0eEXE\u540c\u76ee\u5f55&#xff09;&#xff0c;\u4f7f\u7a0b\u5e8f\u4f18\u5148\u52a0\u8f7d\u672c\u5730DLL&#xff0c;\u907f\u514d\u7cfb\u7edf\u4e2d\u5176\u4ed6\u7248\u672c\u7684\u5e72\u6270\u3002\u8fd9\u662f\u6700\u7b80\u5355\u6709\u6548\u7684\u65b9\u6848&#xff0c;\u9002\u7528\u4e8e\u5927\u591a\u6570\u684c\u9762\u5e94\u7528\u3002<\/p>\n<p>\u4f8b\u5982&#xff0c;\u5c06msvcp140.dll\u3001MyMath.dll\u590d\u5236\u5230C:\\\\Program Files\\\\MyApp\\\\&#xff0c;\u7a0b\u5e8f\u8fd0\u884c\u65f6\u4f1a\u4f18\u5148\u52a0\u8f7dC:\\\\Program Files\\\\MyApp\\\\msvcp140.dll&#xff0c;\u800c\u975e\u7cfb\u7edf\u76ee\u5f55\u4e2d\u7684\u7248\u672c\u3002<\/p>\n<h5>7.3.2 \u5e76\u884c\u7a0b\u5e8f\u96c6&#xff08;Side-by-Side Assemblies&#xff0c;SxS&#xff09;<\/h5>\n<p>Windows XP\u53ca\u4ee5\u4e0a\u652f\u6301\u201c\u5e76\u884c\u7a0b\u5e8f\u96c6\u201d&#xff1a;\u5c06\u4e0d\u540c\u7248\u672c\u7684DLL\u653e\u5728C:\\\\Windows\\\\WinSxS\u76ee\u5f55&#xff08;\u79f0\u4e3a\u201c\u5168\u5c40\u7a0b\u5e8f\u96c6\u7f13\u5b58\u201d&#xff09;&#xff0c;\u901a\u8fc7manifest\u6587\u4ef6\u6307\u5b9a\u7a0b\u5e8f\u4f9d\u8d56\u7684DLL\u7248\u672c&#xff0c;\u5b9e\u73b0\u540c\u4e00DLL\u591a\u4e2a\u7248\u672c\u7684\u5171\u5b58\u3002<\/p>\n<p>\u4f8b\u5982&#xff0c;\u7a0b\u5e8f\u7684MyApp.exe.manifest\u6587\u4ef6\u53ef\u6307\u5b9a\u4f9d\u8d56Microsoft.VC140.CRT\u7248\u672c14.0.24215.0&#xff0c;\u7cfb\u7edf\u4f1a\u4eceWinSxS\u52a0\u8f7d\u5bf9\u5e94\u7248\u672c\u7684msvcr140.dll\u3002<\/p>\n<p>\u5e76\u884c\u7a0b\u5e8f\u96c6\u9002\u7528\u4e8e\u7cfb\u7edf\u7ea7DLL&#xff08;\u5982VC\u8fd0\u884c\u65f6&#xff09;&#xff0c;\u4f46\u914d\u7f6e\u590d\u6742&#xff08;\u9700\u7f16\u5199manifest\u6587\u4ef6&#xff09;&#xff0c;\u4e14WinSxS\u76ee\u5f55\u6743\u9650\u4e25\u683c&#xff08;\u666e\u901a\u7528\u6237\u65e0\u6cd5\u4fee\u6539&#xff09;\u3002<\/p>\n<h5>7.3.3 \u9759\u6001\u94fe\u63a5\u5173\u952eDLL<\/h5>\n<p>\u5bf9\u4e8e\u4f9d\u8d56\u7684\u5c0f\u578bDLL&#xff08;\u5982\u81ea\u5b9a\u4e49\u5de5\u5177\u7c7b&#xff09;&#xff0c;\u53ef\u901a\u8fc7\u9759\u6001\u94fe\u63a5\u5c06\u5176\u4ee3\u7801\u5d4c\u5165EXE&#xff0c;\u907f\u514dDLL\u4f9d\u8d56\u3002\u4f46\u4f1a\u589e\u52a0EXE\u4f53\u79ef&#xff0c;\u4e14\u65e0\u6cd5\u5355\u72ec\u66f4\u65b0\u9759\u6001\u94fe\u63a5\u7684\u4ee3\u7801\u3002<\/p>\n<h5>7.3.4 \u5b89\u88c5\u7a0b\u5e8f\u81ea\u52a8\u90e8\u7f72\u4f9d\u8d56<\/h5>\n<p>\u901a\u8fc7\u5b89\u88c5\u7a0b\u5e8f&#xff08;\u5982InstallShield\u3001WiX\u3001NSIS&#xff09;\u5728\u5b89\u88c5\u65f6\u81ea\u52a8\u68c0\u6d4b\u5e76\u5b89\u88c5\u7f3a\u5931\u7684\u4f9d\u8d56DLL&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<ul>\n<li>\u68c0\u6d4b\u662f\u5426\u5b89\u88c5\u4e86.NET Framework&#xff0c;\u82e5\u672a\u5b89\u88c5\u5219\u81ea\u52a8\u4e0b\u8f7d\u5b89\u88c5\u3002<\/li>\n<li>\u6346\u7ed1VC\u8fd0\u884c\u65f6\u5e93&#xff08;vcredist_x64.exe&#xff09;&#xff0c;\u5728\u5b89\u88c5\u7a0b\u5e8f\u65f6\u9759\u9ed8\u5b89\u88c5\u3002<\/li>\n<li>\u5c06\u6240\u6709\u79c1\u6709DLL\u6253\u5305\u5230\u5b89\u88c5\u5305&#xff0c;\u5b89\u88c5\u65f6\u590d\u5236\u5230\u7a0b\u5e8f\u76ee\u5f55\u3002<\/li>\n<\/ul>\n<h5>7.3.5 \u4f7f\u7528DLL\u91cd\u5b9a\u5411&#xff08;DLL Redirection&#xff09;<\/h5>\n<p>\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6&#xff08;exe\u540d\u79f0.config&#xff09;\u6307\u5b9aDLL\u7684\u52a0\u8f7d\u8def\u5f84&#xff0c;\u5f3a\u5236\u7a0b\u5e8f\u52a0\u8f7d\u7279\u5b9a\u7248\u672c\u7684DLL&#xff1a;<\/p>\n<p><span class=\"token comment\">&lt;!&#8211; MyApp.exe.config &#8211;&gt;<\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>configuration<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>windows<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>assemblyBinding<\/span> <span class=\"token attr-name\">xmlns<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>urn:schemas-microsoft-com:asm.v1<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>dependentAssembly<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>assemblyIdentity<\/span> <span class=\"token attr-name\">name<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>MyMath<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">publicKeyToken<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>12345678<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token punctuation\">\/&gt;<\/span><\/span><br \/>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>codeBase<\/span> <span class=\"token attr-name\">version<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>2.0.0.0<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">href<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>.\\\\v2\\\\MyMath.dll<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token punctuation\">\/&gt;<\/span><\/span><br \/>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>dependentAssembly<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>assemblyBinding<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>windows<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>configuration<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<p>\u6b64\u65b9\u6848\u9002\u7528\u4e8e\u9700\u8981\u540c\u65f6\u8fd0\u884c\u591a\u4e2a\u7248\u672cDLL\u7684\u573a\u666f&#xff08;\u5982\u540c\u4e00\u7a0b\u5e8f\u7684\u4e0d\u540c\u63d2\u4ef6\u4f9d\u8d56\u4e0d\u540c\u7248\u672c\u7684\u6838\u5fc3DLL&#xff09;\u3002<\/p>\n<h3>\u516b\u3001DLL\u7684\u5b89\u5168\u4e0e\u653b\u9632&#xff1a;\u52ab\u6301\u3001\u6ce8\u5165\u4e0e\u9632\u62a4<\/h3>\n<p>DLL\u7684\u52a8\u6001\u94fe\u63a5\u673a\u5236\u5b58\u5728\u5929\u7136\u7684\u5b89\u5168\u98ce\u9669&#xff1a;\u653b\u51fb\u8005\u53ef\u901a\u8fc7\u66ff\u6362DLL\u3001\u4f2a\u9020\u5bfc\u51fa\u51fd\u6570\u7b49\u65b9\u5f0f\u52ab\u6301\u7a0b\u5e8f\u6267\u884c\u6d41\u7a0b&#xff0c;\u5b9e\u73b0\u6076\u610f\u76ee\u7684\u3002\u7406\u89e3DLL\u5b89\u5168\u95ee\u9898\u662f\u4fdd\u62a4\u8f6f\u4ef6\u7684\u57fa\u7840\u3002<\/p>\n<h4>8.1 DLL\u52ab\u6301&#xff08;DLL Hijacking&#xff09;<\/h4>\n<p>DLL\u52ab\u6301\u662f\u6307\u653b\u51fb\u8005\u5229\u7528\u7a0b\u5e8f\u52a0\u8f7dDLL\u7684\u641c\u7d22\u987a\u5e8f&#xff0c;\u66ff\u6362\u5408\u6cd5DLL\u4e3a\u6076\u610fDLL&#xff0c;\u4f7f\u7a0b\u5e8f\u5728\u52a0\u8f7d\u65f6\u6267\u884c\u6076\u610f\u4ee3\u7801\u3002<\/p>\n<h5>8.1.1 \u641c\u7d22\u987a\u5e8f\u4e0e\u52ab\u6301\u539f\u7406<\/h5>\n<p>Windows\u52a0\u8f7dDLL\u65f6\u7684\u9ed8\u8ba4\u641c\u7d22\u987a\u5e8f&#xff08;\u7b80\u5316\u7248&#xff09;\u4e3a&#xff1a;<\/p>\n<li>\u7a0b\u5e8f\u5f53\u524d\u76ee\u5f55&#xff08;GetModuleFileName\u8fd4\u56de\u7684EXE\u6240\u5728\u76ee\u5f55&#xff09;\u3002<\/li>\n<li>\u7cfb\u7edf\u76ee\u5f55&#xff08;C:\\\\Windows\\\\System32&#xff09;\u3002<\/li>\n<li>16\u4f4d\u7cfb\u7edf\u76ee\u5f55&#xff08;C:\\\\Windows\\\\System&#xff09;\u3002<\/li>\n<li>Windows\u76ee\u5f55&#xff08;C:\\\\Windows&#xff09;\u3002<\/li>\n<li>\u73af\u5883\u53d8\u91cfPATH\u4e2d\u7684\u76ee\u5f55\u3002<\/li>\n<p>\u653b\u51fb\u8005\u82e5\u80fd\u5728\u7a0b\u5e8f\u7684\u5f53\u524d\u76ee\u5f55\u653e\u7f6e\u4e0e\u5408\u6cd5DLL\u540c\u540d\u7684\u6076\u610fDLL&#xff08;\u5982\u7a0b\u5e8f\u4f9d\u8d56util.dll&#xff0c;\u653b\u51fb\u8005\u653e\u7f6e\u6076\u610futil.dll&#xff09;&#xff0c;\u7a0b\u5e8f\u4f1a\u4f18\u5148\u52a0\u8f7d\u6076\u610fDLL&#xff0c;\u6267\u884c\u5176\u4e2d\u7684DllMain\u51fd\u6570&#xff08;\u5728\u7a0b\u5e8f\u542f\u52a8\u65f6\u81ea\u52a8\u8c03\u7528&#xff09;\u3002<\/p>\n<h5>8.1.2 \u5178\u578b\u52ab\u6301\u573a\u666f<\/h5>\n<li>\n<p>\u8f6f\u4ef6\u5b89\u88c5\u76ee\u5f55\u6743\u9650\u677e\u6563&#xff1a;\u82e5\u7a0b\u5e8f\u5b89\u88c5\u5728C:\\\\Program Files\\\\MyApp&#xff0c;\u4f46\u666e\u901a\u7528\u6237\u6709\u5199\u5165\u6743\u9650&#xff0c;\u653b\u51fb\u8005\u53ef\u5728\u8be5\u76ee\u5f55\u653e\u7f6e\u6076\u610fDLL\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f9d\u8d56\u672a\u6307\u5b9a\u8def\u5f84\u7684DLL&#xff1a;\u7a0b\u5e8f\u901a\u8fc7LoadLibrary(&#034;unknown.dll&#034;)\u52a0\u8f7dDLL&#xff08;\u672a\u6307\u5b9a\u7edd\u5bf9\u8def\u5f84&#xff09;&#xff0c;\u4e14unknown.dll\u4e0d\u5728\u7cfb\u7edf\u76ee\u5f55&#xff0c;\u653b\u51fb\u8005\u53ef\u5728\u641c\u7d22\u8def\u5f84\u4e2d\u4f2a\u9020\u8be5DLL\u3002<\/p>\n<\/li>\n<li>\n<p>\u7f3a\u5931\u7684\u201c\u5ef6\u8fdf\u52a0\u8f7dDLL\u201d&#xff1a;\u7a0b\u5e8f\u4f7f\u7528\u5ef6\u8fdf\u52a0\u8f7d&#xff08;Delay Load&#xff09;\u673a\u5236\u52a0\u8f7d\u67d0\u4e2aDLL&#xff0c;\u4f46\u8be5DLL\u5b9e\u9645\u4e0d\u5b58\u5728&#xff0c;\u653b\u51fb\u8005\u53ef\u521b\u5efa\u540c\u540d\u6076\u610fDLL\u88ab\u52a0\u8f7d\u3002<\/p>\n<\/li>\n<h5>8.1.3 \u9632\u5fa1DLL\u52ab\u6301\u7684\u63aa\u65bd<\/h5>\n<li>\n<p>\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\u52a0\u8f7dDLL&#xff1a;\u8c03\u7528LoadLibrary\u65f6\u6307\u5b9a\u5b8c\u6574\u8def\u5f84&#xff08;\u5982LoadLibrary(&#034;C:\\\\\\\\Program Files\\\\\\\\MyApp\\\\\\\\util.dll&#034;)&#xff09;&#xff0c;\u907f\u514d\u4f9d\u8d56\u641c\u7d22\u987a\u5e8f\u3002<\/p>\n<\/li>\n<li>\n<p>\u9650\u5236\u5b89\u88c5\u76ee\u5f55\u6743\u9650&#xff1a;\u786e\u4fdd\u7a0b\u5e8f\u5b89\u88c5\u76ee\u5f55&#xff08;\u5982C:\\\\Program Files&#xff09;\u4ec5\u7ba1\u7406\u5458\u6709\u5199\u5165\u6743\u9650&#xff0c;\u666e\u901a\u7528\u6237\u65e0\u6cd5\u66ff\u6362DLL\u3002<\/p>\n<\/li>\n<li>\n<p>\u542f\u7528SafeDllSearchMode&#xff1a;\u901a\u8fc7\u6ce8\u518c\u8868HKLM\\\\SYSTEM\\\\CurrentControlSet\\\\Control\\\\Session Manager\\\\SafeDllSearchMode\u8bbe\u7f6e\u4e3a1&#xff08;\u9ed8\u8ba4\u542f\u7528&#xff09;&#xff0c;\u8c03\u6574\u641c\u7d22\u987a\u5e8f&#xff08;\u4f18\u5148\u7cfb\u7edf\u76ee\u5f55&#xff0c;\u518d\u5f53\u524d\u76ee\u5f55&#xff09;&#xff0c;\u51cf\u5c11\u5f53\u524d\u76ee\u5f55\u52ab\u6301\u98ce\u9669\u3002<\/p>\n<\/li>\n<li>\n<p>\u6570\u5b57\u7b7e\u540d\u9a8c\u8bc1&#xff1a;\u52a0\u8f7dDLL\u524d\u901a\u8fc7WinVerifyTrust\u9a8c\u8bc1DLL\u7684\u6570\u5b57\u7b7e\u540d&#xff0c;\u786e\u4fdd\u5176\u6765\u81ea\u53ef\u4fe1\u53d1\u5e03\u8005\u3002<\/p>\n<\/li>\n<li>\n<p>DLL\u7279\u6027\u6807\u8bb0&#xff1a;\u5728\u7a0b\u5e8f\u6e05\u5355\u4e2d\u6307\u5b9adllDependency\u7684name\u4e0epublicKeyToken&#xff0c;\u9650\u5236\u4ec5\u52a0\u8f7d\u7b7e\u540d\u5339\u914d\u7684DLL\u3002<\/p>\n<\/li>\n<h4>8.2 DLL\u6ce8\u5165&#xff08;DLL Injection&#xff09;<\/h4>\n<p>DLL\u6ce8\u5165\u662f\u6307\u5c06\u6076\u610fDLL\u5f3a\u5236\u52a0\u8f7d\u5230\u76ee\u6807\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4&#xff0c;\u4f7f\u6076\u610f\u4ee3\u7801\u5728\u76ee\u6807\u8fdb\u7a0b\u4e2d\u6267\u884c&#xff08;\u5982\u7a83\u53d6\u6570\u636e\u3001\u76d1\u63a7\u884c\u4e3a&#xff09;\u3002<\/p>\n<h5>8.2.1 \u5e38\u89c1\u6ce8\u5165\u65b9\u6cd5<\/h5>\n<li>\n<p>\u8fdc\u7a0b\u7ebf\u7a0b\u6ce8\u5165&#xff08;Remote Thread Injection&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u6253\u5f00\u76ee\u6807\u8fdb\u7a0b&#xff08;OpenProcess\u83b7\u53d6\u53e5\u67c4&#xff09;\u3002<\/li>\n<li>\u5728\u76ee\u6807\u8fdb\u7a0b\u4e2d\u5206\u914d\u5185\u5b58&#xff0c;\u5199\u5165DLL\u8def\u5f84&#xff08;VirtualAllocEx&#xff09;\u3002<\/li>\n<li>\u5728\u76ee\u6807\u8fdb\u7a0b\u4e2d\u521b\u5efa\u8fdc\u7a0b\u7ebf\u7a0b&#xff0c;\u8c03\u7528LoadLibrary\u52a0\u8f7d\u6076\u610fDLL&#xff08;CreateRemoteThread&#xff09;\u3002<\/li>\n<li>\u6076\u610fDLL\u7684DllMain\u5728\u76ee\u6807\u8fdb\u7a0b\u4e2d\u6267\u884c&#xff08;\u5982\u8bb0\u5f55\u952e\u76d8\u8f93\u5165&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>AppInit_DLLs\u6ce8\u5165&#xff1a;<\/p>\n<ul>\n<li>\u4fee\u6539\u6ce8\u518c\u8868HKLM\\\\SOFTWARE\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Windows\\\\AppInit_DLLs&#xff0c;\u6dfb\u52a0\u6076\u610fDLL\u8def\u5f84\u3002<\/li>\n<li>\u6240\u6709\u52a0\u8f7duser32.dll\u7684\u8fdb\u7a0b\u4f1a\u81ea\u52a8\u52a0\u8f7d\u8be5DLL&#xff08;\u9002\u7528\u4e8e\u5168\u5c40\u76d1\u63a7&#xff09;&#xff0c;\u4f46Windows 8\u540e\u9700\u914d\u5408LoadAppInit_DLLs\u8bbe\u7f6e&#xff0c;\u4e14\u88abDefender\u7b49\u5b89\u5168\u8f6f\u4ef6\u76d1\u63a7\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u52ab\u6301\u8fdb\u7a0b\u542f\u52a8&#xff08;Image File Execution Options&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u5728\u6ce8\u518c\u8868HKLM\\\\SOFTWARE\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Image File Execution Options\\\\target.exe\u4e2d\u8bbe\u7f6eDebugger\u4e3a\u6076\u610f\u7a0b\u5e8f\u8def\u5f84\u3002<\/li>\n<li>\u5f53target.exe\u542f\u52a8\u65f6&#xff0c;\u7cfb\u7edf\u4f1a\u5148\u8fd0\u884c\u6076\u610f\u7a0b\u5e8f&#xff0c;\u540e\u8005\u53ef\u52a0\u8f7d\u6076\u610fDLL\u5230target.exe\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u70ed\u8865\u4e01\u6ce8\u5165&#xff08;Hot Patching&#xff09;&#xff1a;\u4fee\u6539\u76ee\u6807\u8fdb\u7a0b\u7684\u4ee3\u7801\u6bb5&#xff08;.text\u8282&#xff09;&#xff0c;\u5c06\u51fd\u6570\u5165\u53e3\u8df3\u8f6c\u5230\u6076\u610fDLL\u7684\u51fd\u6570&#xff0c;\u5b9e\u73b0\u6267\u884c\u6d41\u7a0b\u52ab\u6301&#xff08;\u9700\u5173\u95ed\u5185\u5b58\u4fdd\u62a4PAGE_EXECUTE_READWRITE&#xff09;\u3002<\/p>\n<\/li>\n<h5>8.2.2 DLL\u6ce8\u5165\u7684\u9632\u5fa1\u4e0e\u68c0\u6d4b<\/h5>\n<li>\n<p>\u8fdb\u7a0b\u4fdd\u62a4\u6280\u672f&#xff1a;<\/p>\n<ul>\n<li>\u4f7f\u7528SetProcessMitigationPolicy\u542f\u7528PROCESS_MITIGATION_DLL_LOAD_DISABLE_POLICY&#xff0c;\u9650\u5236\u975e\u7cfb\u7edfDLL\u52a0\u8f7d\u3002<\/li>\n<li>\u542f\u7528Windows Defender Application Control&#xff08;WDAC&#xff09;&#xff0c;\u4ec5\u5141\u8bb8\u7b7e\u540d\u7684DLL\u52a0\u8f7d\u5230\u8fdb\u7a0b\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u884c\u4e3a\u76d1\u63a7&#xff1a;<\/p>\n<ul>\n<li>\u76d1\u63a7\u5f02\u5e38\u7684\u8fdc\u7a0b\u7ebf\u7a0b\u521b\u5efa&#xff08;CreateRemoteThread\u8c03\u7528&#xff09;\u3002<\/li>\n<li>\u68c0\u6d4b\u6ce8\u518c\u8868\u4e2dAppInit_DLLs\u6216Image File Execution Options\u7684\u5f02\u5e38\u4fee\u6539\u3002<\/li>\n<li>\u901a\u8fc7Process Explorer\u67e5\u770b\u8fdb\u7a0b\u52a0\u8f7d\u7684\u975e\u9884\u671fDLL&#xff08;\u5982\u672a\u77e5\u8def\u5f84\u7684inject.dll&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4ee3\u7801\u7b7e\u540d\u9a8c\u8bc1&#xff1a;\u5bf9\u5173\u952e\u8fdb\u7a0b&#xff08;\u5982\u94f6\u884c\u5ba2\u6237\u7aef&#xff09;&#xff0c;\u9a8c\u8bc1\u6240\u6709\u52a0\u8f7d\u7684DLL\u662f\u5426\u6709\u5408\u6cd5\u6570\u5b57\u7b7e\u540d&#xff0c;\u62d2\u7edd\u52a0\u8f7d\u672a\u7b7e\u540d\u7684DLL\u3002<\/p>\n<\/li>\n<h4>8.3 \u5176\u4ed6DLL\u5b89\u5168\u95ee\u9898<\/h4>\n<li>\n<p>\u5bfc\u51fa\u51fd\u6570\u6ee5\u7528&#xff1a;DLL\u4e2d\u672a\u9650\u5236\u8bbf\u95ee\u7684\u5bfc\u51fa\u51fd\u6570\u53ef\u80fd\u88ab\u6076\u610f\u8c03\u7528&#xff0c;\u4f8b\u5982admin.dll\u4e2d\u7684DeleteUser\u51fd\u6570\u82e5\u53ef\u88ab\u4efb\u610f\u7a0b\u5e8f\u8c03\u7528&#xff0c;\u53ef\u80fd\u5bfc\u81f4\u6743\u9650\u6ee5\u7528\u3002\u9632\u5fa1&#xff1a;\u5728\u5bfc\u51fa\u51fd\u6570\u4e2d\u6dfb\u52a0\u6743\u9650\u68c0\u67e5&#xff08;\u5982\u9a8c\u8bc1\u8c03\u7528\u8005\u662f\u5426\u4e3a\u7ba1\u7406\u5458&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u8d44\u6e90 DLL \u4e2d\u7684\u6076\u610f\u4ee3\u7801&#xff1a;\u653b\u51fb\u8005\u53ef\u80fd\u4f2a\u88c5\u8d44\u6e90DLL&#xff08;\u5982icons.dll&#xff09;&#xff0c;\u5728\u8d44\u6e90\u6570\u636e\u4e2d\u5d4c\u5165\u6076\u610f\u4ee3\u7801&#xff0c;\u901a\u8fc7\u6f0f\u6d1e&#xff08;\u5982\u7f13\u51b2\u533a\u6ea2\u51fa&#xff09;\u89e6\u53d1\u6267\u884c\u3002\u9632\u5fa1&#xff1a;\u52a0\u8f7d\u8d44\u6e90DLL\u524d\u9a8c\u8bc1\u7b7e\u540d&#xff0c;\u9650\u5236\u8d44\u6e90\u89e3\u6790\u903b\u8f91&#xff08;\u907f\u514d\u7f13\u51b2\u533a\u6ea2\u51fa&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>DLL\u9884\u52a0\u8f7d\u653b\u51fb&#xff08;Preloading&#xff09;&#xff1a;\u7a0b\u5e8f\u542f\u52a8\u524d&#xff0c;\u653b\u51fb\u8005\u901a\u8fc7\u4fee\u6539\u73af\u5883\u53d8\u91cf\u6216\u7b26\u53f7\u94fe\u63a5&#xff0c;\u4f7f\u7a0b\u5e8f\u52a0\u8f7d\u6076\u610fDLL&#xff08;\u5982\u5c06PATH\u6307\u5411\u542b\u6076\u610fDLL\u7684\u76ee\u5f55&#xff09;\u3002\u9632\u5fa1&#xff1a;\u907f\u514d\u4f9d\u8d56\u73af\u5883\u53d8\u91cf\u52a0\u8f7dDLL&#xff0c;\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\u3002<\/p>\n<\/li>\n<h3>\u4e5d\u3001DLL\u7684\u8c03\u8bd5\u4e0e\u8bca\u65ad&#xff1a;\u4ece\u9519\u8bef\u5230\u4f18\u5316<\/h3>\n<p>DLL\u7684\u8c03\u8bd5\u4e0e\u8bca\u65ad\u662f\u89e3\u51b3\u52a0\u8f7d\u5931\u8d25\u3001\u5d29\u6e83\u3001\u6027\u80fd\u95ee\u9898\u7684\u5173\u952e&#xff0c;\u9700\u7ed3\u5408\u5de5\u5177\u4e0e\u6280\u672f\u624b\u6bb5\u5b9a\u4f4d\u6839\u56e0\u3002<\/p>\n<h4>9.1 DLL\u52a0\u8f7d\u5931\u8d25\u7684\u8c03\u8bd5<\/h4>\n<h5>9.1.1 \u5e38\u89c1\u52a0\u8f7d\u5931\u8d25\u539f\u56e0\u4e0e\u6392\u67e5<\/h5>\n<li>\n<p>\u6587\u4ef6\u4e0d\u5b58\u5728&#xff1a;<\/p>\n<ul>\n<li>\u68c0\u67e5DLL\u662f\u5426\u5728\u641c\u7d22\u8def\u5f84\u4e2d&#xff08;\u5f53\u524d\u76ee\u5f55\u3001\u7cfb\u7edf\u76ee\u5f55\u3001PATH&#xff09;\u3002<\/li>\n<li>\u4f7f\u7528where\u547d\u4ee4&#xff08;CMD&#xff09;\u6216Get-Command&#xff08;PowerShell&#xff09;\u67e5\u627e\u7cfb\u7edf\u4e2d\u662f\u5426\u5b58\u5728\u8be5DLL&#xff1a;where msvcp140.dll\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7248\u672c\u4e0d\u5339\u914d&#xff1a;<\/p>\n<ul>\n<li>32\u4f4d\u7a0b\u5e8f\u52a0\u8f7d64\u4f4dDLL&#xff08;\u6216\u53cd\u4e4b&#xff09;&#xff1a;\u901a\u8fc7dumpbin \/headers MyDll.dll\u67e5\u770bDLL\u7684\u4f4d\u6570&#xff08;\u201cmachine (x86)\u201d\u6216\u201cmachine (x64)\u201d&#xff09;&#xff0c;\u786e\u4fdd\u4e0e\u8c03\u7528\u7a0b\u5e8f\u4e00\u81f4\u3002<\/li>\n<li>.NET\u7248\u672c\u4e0d\u5339\u914d&#xff1a;\u6258\u7ba1DLL\u4f9d\u8d56\u7684.NET\u7248\u672c\u9ad8\u4e8e\u7cfb\u7edf\u5b89\u88c5\u7248\u672c&#xff0c;\u9700\u5b89\u88c5\u5bf9\u5e94.NET Framework\/.NET Core\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6743\u9650\u4e0d\u8db3&#xff1a;<\/p>\n<ul>\n<li>DLL\u6587\u4ef6\u6216\u76ee\u5f55\u6743\u9650\u8bbe\u7f6e\u4e0d\u5f53&#xff08;\u5982\u666e\u901a\u7528\u6237\u65e0\u8bfb\u53d6\u6743\u9650&#xff09;&#xff0c;\u901a\u8fc7\u201c\u5c5e\u6027\u2192\u5b89\u5168\u201d\u68c0\u67e5\u6743\u9650\u3002<\/li>\n<li>\u7cfb\u7edfDLL\u88abWFP&#xff08;Windows\u6587\u4ef6\u4fdd\u62a4&#xff09;\u9501\u5b9a&#xff0c;\u65e0\u6cd5\u66ff\u6362\u6216\u4fee\u6539&#xff08;\u9700\u7981\u7528WFP&#xff0c;\u4e0d\u5efa\u8bae&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4f9d\u8d56\u94fe\u65ad\u88c2&#xff1a;<\/p>\n<ul>\n<li>\u4f7f\u7528Dependency Walker\u6253\u5f00DLL&#xff0c;\u67e5\u770b\u7ea2\u8272\u6807\u8bb0\u7684\u7f3a\u5931\u4f9d\u8d56&#xff08;\u201cMissing DLL\u201d&#xff09;&#xff0c;\u5b89\u88c5\u5bf9\u5e94\u4f9d\u8d56\u3002<\/li>\n<\/ul>\n<\/li>\n<h5>9.1.2 \u8c03\u8bd5\u5de5\u5177\u4e0e\u6280\u672f<\/h5>\n<li>\n<p>Dependency Walker\u7684\u201cProfile\u201d\u529f\u80fd&#xff1a;<\/p>\n<ul>\n<li>\u70b9\u51fb\u201cProfile\u2192Start Profiling\u201d&#xff0c;\u8f93\u5165\u7a0b\u5e8f\u8def\u5f84&#xff0c;\u8ddf\u8e2aDLL\u52a0\u8f7d\u8fc7\u7a0b&#xff0c;\u5728\u65e5\u5fd7\u4e2d\u67e5\u770b\u52a0\u8f7d\u5931\u8d25\u7684\u5177\u4f53\u6b65\u9aa4&#xff08;\u5982\u201c\u627e\u4e0d\u5230\u4f9d\u8d56xxx.dll\u201d&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Process Monitor&#xff08;ProcMon&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u8fc7\u6ee4\u201cProcess Name\u201d\u4e3a\u76ee\u6807\u7a0b\u5e8f&#xff0c;\u201cOperation\u201d\u4e3a\u201cCreateFile\u201d&#xff08;DLL\u52a0\u8f7d\u65f6\u4f1a\u5c1d\u8bd5\u6253\u5f00\u6587\u4ef6&#xff09;&#xff0c;\u67e5\u770b\u201cResult\u201d\u4e3a\u201cNAME NOT FOUND\u201d\u7684\u8bb0\u5f55&#xff0c;\u5b9a\u4f4d\u7f3a\u5931\u7684DLL\u8def\u5f84\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4e8b\u4ef6\u67e5\u770b\u5668&#xff1a;<\/p>\n<ul>\n<li>\u67e5\u770b\u201cWindows\u65e5\u5fd7\u2192\u7cfb\u7edf\u201d&#xff0c;\u7b5b\u9009\u6765\u6e90\u4e3a\u201cApplication Error\u201d\u7684\u4e8b\u4ef6&#xff0c;\u83b7\u53d6DLL\u52a0\u8f7d\u5931\u8d25\u7684\u9519\u8bef\u4ee3\u7801&#xff08;\u59820x80070002\u8868\u793a\u6587\u4ef6\u672a\u627e\u5230&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u8c03\u8bd5\u5668&#xff08;Visual Studio\/WinDbg&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u5728\u7a0b\u5e8f\u542f\u52a8\u65f6\u9644\u52a0\u8c03\u8bd5\u5668&#xff0c;\u8bbe\u7f6e\u65ad\u70b9LoadLibraryW&#xff0c;\u5355\u6b65\u8ddf\u8e2aDLL\u52a0\u8f7d\u8fc7\u7a0b&#xff0c;\u67e5\u770b\u8fd4\u56de\u7684\u9519\u8bef\u7801&#xff08;\u901a\u8fc7GetLastError&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<h4>9.2 DLL\u5f15\u53d1\u7684\u5d29\u6e83\u8c03\u8bd5<\/h4>\n<p>DLL\u8c03\u7528\u5bfc\u81f4\u7684\u5d29\u6e83&#xff08;\u59820xC0000005\u8bbf\u95ee\u51b2\u7a81&#xff09;\u901a\u5e38\u4e0e\u51fd\u6570\u8c03\u7528\u9519\u8bef\u6216\u5185\u5b58\u95ee\u9898\u76f8\u5173&#xff0c;\u8c03\u8bd5\u6b65\u9aa4\u5982\u4e0b&#xff1a;<\/p>\n<li>\n<p>\u83b7\u53d6\u5d29\u6e83\u8f6c\u50a8&#xff08;Crash Dump&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u901a\u8fc7\u4efb\u52a1\u7ba1\u7406\u5668\u53f3\u952e\u8fdb\u7a0b\u2192\u201c\u521b\u5efa\u8f6c\u50a8\u6587\u4ef6\u201d&#xff0c;\u751f\u6210.dmp\u6587\u4ef6\u3002<\/li>\n<li>\u542f\u7528Windows\u9519\u8bef\u62a5\u544a&#xff08;WER&#xff09;&#xff0c;\u81ea\u52a8\u6536\u96c6\u5d29\u6e83\u8f6c\u50a8&#xff08;\u9ed8\u8ba4\u8def\u5f84C:\\\\ProgramData\\\\Microsoft\\\\Windows\\\\WER\\\\ReportArchive&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5206\u6790\u8f6c\u50a8\u6587\u4ef6&#xff1a;<\/p>\n<ul>\n<li>\u5728Visual Studio\u4e2d\u6253\u5f00.dmp\u6587\u4ef6&#xff0c;\u67e5\u770b\u201c\u8c03\u7528\u5806\u6808&#xff08;Call Stack&#xff09;\u201d&#xff0c;\u5b9a\u4f4d\u5d29\u6e83\u53d1\u751f\u7684\u51fd\u6570&#xff08;\u5982MyDll!Add&#043;0x12&#xff09;\u3002<\/li>\n<li>\u4f7f\u7528WinDbg&#xff1a;\u52a0\u8f7d\u8f6c\u50a8\u6587\u4ef6\u540e&#xff0c;\u6267\u884c!analyze -v\u81ea\u52a8\u5206\u6790\u5d29\u6e83\u539f\u56e0&#xff0c;\u67e5\u770bFAULTING_IP&#xff08;\u5d29\u6e83\u5730\u5740&#xff09;\u4e0eSTACK_TEXT&#xff08;\u8c03\u7528\u5806\u6808&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5e38\u89c1\u5d29\u6e83\u539f\u56e0\u5b9a\u4f4d&#xff1a;<\/p>\n<ul>\n<li>\u8c03\u7528\u7ea6\u5b9a\u4e0d\u5339\u914d&#xff1a;C&#043;&#043;\u7684__cdecl&#xff08;\u8c03\u7528\u8005\u6e05\u7406\u6808&#xff09;\u4e0e__stdcall&#xff08;\u88ab\u8c03\u7528\u8005\u6e05\u7406\u6808&#xff09;\u6df7\u7528&#xff0c;\u5bfc\u81f4\u6808\u6307\u9488\u5931\u8861\u3002\u901a\u8fc7\u8c03\u8bd5\u5668\u67e5\u770b\u6808\u72b6\u6001&#xff0c;\u5bf9\u6bd4\u9884\u671f\u4e0e\u5b9e\u9645\u6808\u6307\u9488\u3002<\/li>\n<li>\u51fd\u6570\u53c2\u6570\u9519\u8bef&#xff1a;\u4f20\u9012\u7684\u53c2\u6570\u7c7b\u578b\u6216\u6570\u91cf\u4e0eDLL\u5bfc\u51fa\u51fd\u6570\u4e0d\u4e00\u81f4&#xff08;\u5982\u4f20\u9012char*\u7ed9\u671f\u671bwchar_t*\u7684\u51fd\u6570&#xff09;&#xff0c;\u5bfc\u81f4\u5185\u5b58\u8bbf\u95ee\u8d8a\u754c\u3002\u68c0\u67e5\u51fd\u6570\u6307\u9488\u58f0\u660e\u4e0eDLL\u5bfc\u51fa\u662f\u5426\u4e00\u81f4\u3002<\/li>\n<li>DLL\u5df2\u5378\u8f7d\u540e\u8c03\u7528&#xff1a;\u7a0b\u5e8f\u5728FreeLibrary\u540e\u4ecd\u8c03\u7528DLL\u51fd\u6570&#xff08;\u60ac\u7a7a\u6307\u9488&#xff09;&#xff0c;\u901a\u8fc7\u5f15\u7528\u8ba1\u6570\u76d1\u63a7&#xff08;LoadLibrary\/FreeLibrary\u6b21\u6570&#xff09;\u786e\u8ba4\u662f\u5426\u63d0\u524d\u5378\u8f7d\u3002<\/li>\n<li>\u5168\u5c40\u53d8\u91cf\u521d\u59cb\u5316\u987a\u5e8f&#xff1a;DLL\u7684\u5168\u5c40\u53d8\u91cf\u521d\u59cb\u5316\u4f9d\u8d56\u5176\u4ed6DLL&#xff08;\u5982A.dll\u7684\u5168\u5c40\u53d8\u91cf\u521d\u59cb\u5316\u8c03\u7528B.dll\u7684\u51fd\u6570&#xff09;&#xff0c;\u82e5B.dll\u5c1a\u672a\u521d\u59cb\u5316&#xff0c;\u4f1a\u5bfc\u81f4\u5d29\u6e83\u3002\u901a\u8fc7DllMain\u4e2d\u7684\u65ad\u70b9\u786e\u8ba4\u521d\u59cb\u5316\u987a\u5e8f\u3002<\/li>\n<\/ul>\n<\/li>\n<h4>9.3 DLL\u7684\u6027\u80fd\u4f18\u5316<\/h4>\n<p>DLL\u7684\u4e0d\u5408\u7406\u4f7f\u7528\u53ef\u80fd\u5bfc\u81f4\u6027\u80fd\u95ee\u9898&#xff08;\u5982\u52a0\u8f7d\u7f13\u6162\u3001\u8c03\u7528\u8017\u65f6&#xff09;&#xff0c;\u4f18\u5316\u65b9\u5411\u5305\u62ec&#xff1a;<\/p>\n<li>\n<p>\u51cf\u5c11DLL\u6570\u91cf&#xff1a;\u8fc7\u591aDLL\u4f1a\u589e\u52a0\u52a0\u8f7d\u65f6\u95f4&#xff08;\u6bcf\u4e2aDLL\u9700\u89e3\u6790\u5bfc\u5165\u8868\u3001\u91cd\u5b9a\u4f4d&#xff09;&#xff0c;\u5c06\u529f\u80fd\u76f8\u8fd1\u7684DLL\u5408\u5e76\u3002<\/p>\n<\/li>\n<li>\n<p>\u5ef6\u8fdf\u52a0\u8f7d\u975e\u5173\u952eDLL&#xff1a;\u5bf9\u542f\u52a8\u65f6\u4e0d\u5fc5\u987b\u7684DLL&#xff08;\u5982\u5e2e\u52a9\u6587\u6863\u6a21\u5757&#xff09;&#xff0c;\u4f7f\u7528Visual Studio\u7684\u201c\u5ef6\u8fdf\u52a0\u8f7d\u201d\u529f\u80fd&#xff08;\u9879\u76ee\u5c5e\u6027\u2192\u94fe\u63a5\u5668\u2192\u8f93\u5165\u2192\u201c\u5ef6\u8fdf\u52a0\u8f7d\u7684DLL\u201d&#xff09;&#xff0c;\u5728\u9996\u6b21\u8c03\u7528\u65f6\u624d\u52a0\u8f7d\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f18\u5316\u91cd\u5b9a\u4f4d&#xff1a;<\/p>\n<ul>\n<li>\u4e3aDLL\u6307\u5b9a\u552f\u4e00\u7684\u9ed8\u8ba4\u52a0\u8f7d\u5730\u5740&#xff08;\u9879\u76ee\u5c5e\u6027\u2192\u94fe\u63a5\u5668\u2192\u9ad8\u7ea7\u2192\u201c\u57fa\u5740\u201d&#xff09;&#xff0c;\u51cf\u5c11\u52a0\u8f7d\u65f6\u7684\u91cd\u5b9a\u4f4d\u64cd\u4f5c&#xff08;\u91cd\u5b9a\u4f4d\u4f1a\u4fee\u6539\u4ee3\u7801&#xff0c;\u89e6\u53d1\u5185\u5b58\u9875\u5199\u64cd\u4f5c&#xff0c;\u964d\u4f4e\u6027\u80fd&#xff09;\u3002<\/li>\n<li>\u5bf9\u5927\u578bDLL&#xff0c;\u542f\u7528\u201c\u589e\u91cf\u94fe\u63a5\u201d&#xff08;\/INCREMENTAL&#xff09;&#xff0c;\u51cf\u5c11\u91cd\u5b9a\u4f4d\u8868\u5927\u5c0f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u51cf\u5c11\u5bfc\u51fa\u51fd\u6570\u6570\u91cf&#xff1a;\u4ec5\u5bfc\u51fa\u5fc5\u8981\u7684\u51fd\u6570&#xff08;\u907f\u514d__declspec(dllexport)\u4fee\u9970\u975e\u516c\u5f00\u51fd\u6570&#xff09;&#xff0c;\u7f29\u5c0f\u5bfc\u51fa\u8868\u4f53\u79ef&#xff0c;\u52a0\u5feb\u5bfc\u5165\u8868\u89e3\u6790\u3002<\/p>\n<\/li>\n<li>\n<p>\u76d1\u63a7DLL\u8c03\u7528\u6027\u80fd&#xff1a;<\/p>\n<ul>\n<li>\u4f7f\u7528Visual Studio\u7684\u201c\u6027\u80fd\u63a2\u67e5\u5668\u201d&#xff0c;\u8ddf\u8e2aDLL\u51fd\u6570\u7684\u8c03\u7528\u6b21\u6570\u4e0e\u8017\u65f6&#xff0c;\u5b9a\u4f4d\u6027\u80fd\u74f6\u9888&#xff08;\u5982encrypt.dll\u7684AES_Encrypt\u8017\u65f6\u8fc7\u957f&#xff09;\u3002<\/li>\n<li>\u901a\u8fc7QueryPerformanceCounter\u5728\u4ee3\u7801\u4e2d\u57cb\u70b9&#xff0c;\u6d4b\u91cfDLL\u51fd\u6570\u7684\u6267\u884c\u65f6\u95f4\u3002<\/li>\n<\/ul>\n<\/li>\n<h3>\u5341\u3001DLL\u7684\u8de8\u5e73\u53f0\u5bf9\u6bd4\u4e0e\u672a\u6765\u53d1\u5c55<\/h3>\n<p>DLL\u662fWindows\u7279\u6709\u7684\u52a8\u6001\u94fe\u63a5\u6280\u672f&#xff0c;\u4f46\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\u4e5f\u6709\u7c7b\u4f3c\u673a\u5236&#xff1b;\u540c\u65f6&#xff0c;\u968f\u7740\u8f6f\u4ef6\u6280\u672f\u7684\u53d1\u5c55&#xff0c;DLL\u7684\u5f62\u6001\u4e0e\u5e94\u7528\u573a\u666f\u4e5f\u5728\u4e0d\u65ad\u6f14\u53d8\u3002<\/p>\n<h4>10.1 \u8de8\u5e73\u53f0\u52a8\u6001\u94fe\u63a5\u6280\u672f\u5bf9\u6bd4<\/h4>\n<h5>10.1.1 Linux\u7684\u5171\u4eab\u5bf9\u8c61&#xff08;Shared Object&#xff0c;.so&#xff09;<\/h5>\n<p>Linux\u7684.so\u6587\u4ef6\u4e0eDLL\u529f\u80fd\u76f8\u4f3c&#xff0c;\u90fd\u662f\u52a8\u6001\u94fe\u63a5\u5e93&#xff0c;\u4f46\u5176\u8bbe\u8ba1\u4e0e\u5b9e\u73b0\u5b58\u5728\u5dee\u5f02&#xff1a;<\/p>\n<table>\n<tr>\u7279\u6027Windows DLLLinux .so<\/tr>\n<tbody>\n<tr>\n<td>\u6587\u4ef6\u683c\u5f0f<\/td>\n<td>PE&#xff08;Portable Executable&#xff09;<\/td>\n<td>ELF&#xff08;Executable and Linkable Format&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5bfc\u51fa\/\u5bfc\u5165\u8868<\/td>\n<td>\u663e\u5f0f\u5bfc\u51fa\u8868&#xff08;.edata&#xff09;\u3001\u5bfc\u5165\u8868&#xff08;.idata&#xff09;<\/td>\n<td>\u7b26\u53f7\u8868&#xff08;.dynsym&#xff09;\u3001\u91cd\u5b9a\u4f4d\u8868&#xff08;.rel.dyn&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u52a0\u8f7dAPI<\/td>\n<td>LoadLibrary\/GetProcAddress<\/td>\n<td>dlopen\/dlsym<\/td>\n<\/tr>\n<tr>\n<td>\u547d\u540d\u89c4\u5219<\/td>\n<td>\u901a\u5e38\u65e0\u7248\u672c\u540e\u7f00&#xff08;\u5982util.dll&#xff09;<\/td>\n<td>\u542b\u7248\u672c\u53f7&#xff08;\u5982libutil.so.1.2&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u7248\u672c\u517c\u5bb9<\/td>\n<td>\u4f9d\u8d56\u5bfc\u51fa\u51fd\u6570\u7b7e\u540d&#xff0c;\u65e0\u4e25\u683c\u7248\u672c\u673a\u5236<\/td>\n<td>\u9075\u5faa\u8bed\u4e49\u5316\u7248\u672c&#xff08;Major.Minor.Patch&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u641c\u7d22\u8def\u5f84<\/td>\n<td>\u5f53\u524d\u76ee\u5f55\u2192\u7cfb\u7edf\u76ee\u5f55\u2192PATH<\/td>\n<td>LD_LIBRARY_PATH\u2192\/lib\u2192\/usr\/lib<\/td>\n<\/tr>\n<tr>\n<td>\u5165\u53e3\u51fd\u6570<\/td>\n<td>DllMain&#xff08;\u53ef\u9009&#xff09;<\/td>\n<td>\u65e0\u9ed8\u8ba4\u5165\u53e3&#xff0c;\u9700\u663e\u5f0f\u6ce8\u518c\u521d\u59cb\u5316\u51fd\u6570<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>.so\u7684\u4f18\u52bf\u662f\u7248\u672c\u7ba1\u7406\u66f4\u89c4\u8303&#xff08;\u901a\u8fc7soname\u673a\u5236&#xff0c;\u5982libutil.so.1\u6307\u5411libutil.so.1.2&#xff09;&#xff0c;\u4f46\u8de8\u7248\u672c\u517c\u5bb9\u6027\u9700\u5f00\u53d1\u8005\u624b\u52a8\u4fdd\u8bc1&#xff08;\u5982\u907f\u514d\u5220\u9664\u5bfc\u51fa\u51fd\u6570&#xff09;\u3002<\/p>\n<h5>10.1.2 macOS\u7684\u52a8\u6001\u5e93&#xff08;.dylib&#xff09;<\/h5>\n<p>macOS\u7684.dylib&#xff08;Dynamic Library&#xff09;\u662f\u5176\u52a8\u6001\u94fe\u63a5\u6280\u672f&#xff0c;\u57fa\u4e8eMach-O\u683c\u5f0f&#xff0c;\u4e0eDLL\u7684\u5dee\u5f02\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>\u4f9d\u8d56\u201c\u6846\u67b6&#xff08;Framework&#xff09;\u201d&#xff1a;\u591a\u4e2a.dylib\u4e0e\u8d44\u6e90\u6587\u4ef6\u6253\u5305\u4e3a\u6846\u67b6&#xff08;\u5982Cocoa.framework&#xff09;&#xff0c;\u7b80\u5316\u4f9d\u8d56\u7ba1\u7406\u3002<\/li>\n<li>\u52a0\u8f7d\u673a\u5236&#xff1a;\u901a\u8fc7dyld&#xff08;\u52a8\u6001\u94fe\u63a5\u5668&#xff09;\u52a0\u8f7d&#xff0c;\u652f\u6301\u201c\u5ef6\u8fdf\u7ed1\u5b9a\u201d&#xff08;Lazy Binding&#xff09;&#xff0c;\u9996\u6b21\u8c03\u7528\u51fd\u6570\u65f6\u624d\u89e3\u6790\u5730\u5740&#xff08;\u7c7b\u4f3cWindows\u7684\u5ef6\u8fdf\u52a0\u8f7d&#xff09;\u3002<\/li>\n<li>\u5b89\u5168\u7279\u6027&#xff1a;\u652f\u6301\u4ee3\u7801\u7b7e\u540d\u4e0e\u6c99\u7bb1\u673a\u5236&#xff0c;\u672a\u7b7e\u540d\u7684.dylib\u5728\u6c99\u7bb1\u4e2d\u53ef\u80fd\u88ab\u7981\u6b62\u52a0\u8f7d\u3002<\/li>\n<\/ul>\n<h5>10.1.3 Java\u7684JAR\u4e0e.NET\u7684Assembly<\/h5>\n<ul>\n<li>JAR&#xff08;Java Archive&#xff09;&#xff1a;Java\u7684\u5f52\u6863\u6587\u4ef6&#xff0c;\u5305\u542b\u5b57\u8282\u7801\u4e0e\u8d44\u6e90&#xff0c;\u672c\u8d28\u662f\u591a\u4e2a.class\u6587\u4ef6\u7684\u538b\u7f29\u5305&#xff0c;\u901a\u8fc7\u7c7b\u52a0\u8f7d\u5668\u52a8\u6001\u52a0\u8f7d&#xff08;\u7c7b\u4f3cDLL\u7684\u4ee3\u7801\u590d\u7528&#xff09;&#xff0c;\u4f46\u4f9d\u8d56JVM&#xff0c;\u4e0eDLL\u7684\u673a\u5668\u7801\u6267\u884c\u65b9\u5f0f\u4e0d\u540c\u3002<\/li>\n<li>.NET Assembly&#xff08;\u7a0b\u5e8f\u96c6&#xff09;&#xff1a;.NET\u7684\u57fa\u672c\u90e8\u7f72\u5355\u4f4d&#xff08;.dll\u6216.exe&#xff09;&#xff0c;\u5305\u542bIL\u4ee3\u7801\u3001\u5143\u6570\u636e\u3001\u8d44\u6e90&#xff0c;\u7531CLR\u52a0\u8f7d\u6267\u884c&#xff0c;\u517c\u5177DLL\u7684\u52a8\u6001\u94fe\u63a5\u4e0eJAR\u7684\u8de8\u5e73\u53f0\u7279\u6027&#xff0c;\u4f46\u9700.NET\u8fd0\u884c\u65f6\u652f\u6301\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u6280\u672f\u4e0eDLL\u7684\u6838\u5fc3\u76ee\u6807\u4e00\u81f4&#xff08;\u4ee3\u7801\u590d\u7528\u3001\u6a21\u5757\u5316&#xff09;&#xff0c;\u4f46\u5e95\u5c42\u6267\u884c\u73af\u5883\u4e0d\u540c&#xff08;\u865a\u62df\u673avs\u539f\u751f\u7cfb\u7edf&#xff09;\u3002<\/p>\n<h4>10.2 DLL\u7684\u672a\u6765\u53d1\u5c55\u8d8b\u52bf<\/h4>\n<h5>10.2.1 \u5bb9\u5668\u5316\u4e0e\u5fae\u670d\u52a1\u5bf9DLL\u7684\u5f71\u54cd<\/h5>\n<p>\u5bb9\u5668\u5316&#xff08;\u5982Docker&#xff09;\u4e0e\u5fae\u670d\u52a1\u67b6\u6784\u5c06\u8f6f\u4ef6\u62c6\u5206\u4e3a\u72ec\u7acb\u8fd0\u884c\u7684\u670d\u52a1&#xff0c;\u6bcf\u4e2a\u670d\u52a1\u5305\u542b\u81ea\u8eab\u7684\u4f9d\u8d56&#xff08;\u5305\u62ecDLL&#xff09;&#xff0c;\u51cf\u5c11\u4e86\u7cfb\u7edf\u7ea7DLL\u7684\u7248\u672c\u51b2\u7a81&#xff08;\u201c\u4f9d\u8d56\u5730\u72f1\u201d\u7f13\u89e3&#xff09;\u3002\u4f46\u5bb9\u5668\u5185\u7684\u5e94\u7528\u4ecd\u9700DLL\u5b9e\u73b0\u6a21\u5757\u5316&#xff0c;\u4f8b\u5982Windows\u5bb9\u5668\u4e2d\u7684.NET\u5e94\u7528\u4ecd\u4f9d\u8d56clr.dll\u7b49\u6838\u5fc3DLL\u3002<\/p>\n<h5>10.2.2 \u5b89\u5168\u5f3a\u5316\u4e0e\u786c\u4ef6\u652f\u6301<\/h5>\n<p>\u672a\u6765DLL\u53ef\u80fd\u66f4\u6df1\u5ea6\u6574\u5408\u786c\u4ef6\u5b89\u5168\u7279\u6027&#xff1a;<\/p>\n<ul>\n<li>\u7ed3\u5408Intel SGX\u6216AMD SEV&#xff0c;\u5c06\u654f\u611fDLL&#xff08;\u5982\u52a0\u5bc6\u6a21\u5757&#xff09;\u52a0\u8f7d\u5230\u53ef\u4fe1\u6267\u884c\u73af\u5883&#xff08;TEE&#xff09;&#xff0c;\u9632\u6b62\u5185\u5b58\u55c5\u63a2\u3002<\/li>\n<li>\u64cd\u4f5c\u7cfb\u7edf\u53ef\u80fd\u5f3a\u5236\u6240\u6709D<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf13\u6b21\u3002DLL\u901a\u8fc7\u52a8\u6001\u94fe\u63a5\u673a\u5236\u4e3a\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u5171\u4eab\u529f\u80fd\u652f\u6301\u3002\u672c\u6587\u4eceDLL\u7684\u5b9a\u4e49\u3001\u53d1\u5c55\u5386\u53f2\u548c\u6587\u4ef6\u7ed3\u6784\u4e09\u65b9\u9762\u5c55\u5f00\u5206\u6790\uff1a \u672c\u8d28\u4e0e\u4ef7\u503c\uff1aDLL\u662f\u5305\u542b\u53ef\u6267\u884c\u4ee3\u7801\u548c\u6570\u636e\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u901a\u8fc7\u8fd0\u884c\u65f6\u52a0\u8f7d\u5b9e\u73b0\u4ee3\u7801\u590d\u7528\u3001\u8d44\u6e90\u8282\u7701\u548c\u6a21\u5757\u5316\u5f00\u53d1\uff0c\u4e0eEXE\u6587\u4ef6\u5728\u529f\u80fd\u5b9a\u4f4d\u548c\u6267\u884c\u65b9\u5f0f\u4e0a\u6709\u672c\u8d28\u533a\u522b\u3002 \u6f14\u8fdb\u5386\u7a0b\uff1a\u4eceDOS\u65f6\u4ee3\u7684\u9759\u6001\u94fe\u63a5\u56f0\u5883\uff0c\u5230Windows 95\u5f15\u5165\u6210\u719f\u7684DLL\u673a\u5236\uff0c\u518d\u5230.NET\u6846\u67b6\u4e0b\u7684\u6258\u7ba1DLL\uff0cDLL\u6280\u672f\u4e0d\u65ad\u6f14\u8fdb\uff0c\u5df2\u6210\u4e3aWindows\u751f\u6001\u7684\u6838\u5fc3\u652f\u67f1\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[149,4507,16,44,250],"topic":[],"class_list":["post-47143","post","type-post","status-publish","format-standard","hentry","category-server","tag-windows","tag-4507","tag-16","tag-44","tag-250"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Windows-\u52a8\u6001\u94fe\u63a5\u5e93Dynamic Link Library\uff08.dll\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/47143.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Windows-\u52a8\u6001\u94fe\u63a5\u5e93Dynamic Link Library\uff08.dll\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf13\u6b21\u3002DLL\u901a\u8fc7\u52a8\u6001\u94fe\u63a5\u673a\u5236\u4e3a\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u5171\u4eab\u529f\u80fd\u652f\u6301\u3002\u672c\u6587\u4eceDLL\u7684\u5b9a\u4e49\u3001\u53d1\u5c55\u5386\u53f2\u548c\u6587\u4ef6\u7ed3\u6784\u4e09\u65b9\u9762\u5c55\u5f00\u5206\u6790\uff1a \u672c\u8d28\u4e0e\u4ef7\u503c\uff1aDLL\u662f\u5305\u542b\u53ef\u6267\u884c\u4ee3\u7801\u548c\u6570\u636e\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u901a\u8fc7\u8fd0\u884c\u65f6\u52a0\u8f7d\u5b9e\u73b0\u4ee3\u7801\u590d\u7528\u3001\u8d44\u6e90\u8282\u7701\u548c\u6a21\u5757\u5316\u5f00\u53d1\uff0c\u4e0eEXE\u6587\u4ef6\u5728\u529f\u80fd\u5b9a\u4f4d\u548c\u6267\u884c\u65b9\u5f0f\u4e0a\u6709\u672c\u8d28\u533a\u522b\u3002 \u6f14\u8fdb\u5386\u7a0b\uff1a\u4eceDOS\u65f6\u4ee3\u7684\u9759\u6001\u94fe\u63a5\u56f0\u5883\uff0c\u5230Windows 95\u5f15\u5165\u6210\u719f\u7684DLL\u673a\u5236\uff0c\u518d\u5230.NET\u6846\u67b6\u4e0b\u7684\u6258\u7ba1DLL\uff0cDLL\u6280\u672f\u4e0d\u65ad\u6f14\u8fdb\uff0c\u5df2\u6210\u4e3aWindows\u751f\u6001\u7684\u6838\u5fc3\u652f\u67f1\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/47143.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-29T22:31:48+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"21 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/47143.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/47143.html\",\"name\":\"Windows-\u52a8\u6001\u94fe\u63a5\u5e93Dynamic Link Library\uff08.dll\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-29T22:31:48+00:00\",\"dateModified\":\"2025-07-29T22:31:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/47143.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/47143.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/47143.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Windows---\u52a8\u6001\u94fe\u63a5\u5e93Dynamic Link Library\uff08.dll\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Windows-\u52a8\u6001\u94fe\u63a5\u5e93Dynamic Link Library\uff08.dll\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/47143.html","og_locale":"zh_CN","og_type":"article","og_title":"Windows-\u52a8\u6001\u94fe\u63a5\u5e93Dynamic Link Library\uff08.dll\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf13\u6b21\u3002DLL\u901a\u8fc7\u52a8\u6001\u94fe\u63a5\u673a\u5236\u4e3a\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u5171\u4eab\u529f\u80fd\u652f\u6301\u3002\u672c\u6587\u4eceDLL\u7684\u5b9a\u4e49\u3001\u53d1\u5c55\u5386\u53f2\u548c\u6587\u4ef6\u7ed3\u6784\u4e09\u65b9\u9762\u5c55\u5f00\u5206\u6790\uff1a \u672c\u8d28\u4e0e\u4ef7\u503c\uff1aDLL\u662f\u5305\u542b\u53ef\u6267\u884c\u4ee3\u7801\u548c\u6570\u636e\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u901a\u8fc7\u8fd0\u884c\u65f6\u52a0\u8f7d\u5b9e\u73b0\u4ee3\u7801\u590d\u7528\u3001\u8d44\u6e90\u8282\u7701\u548c\u6a21\u5757\u5316\u5f00\u53d1\uff0c\u4e0eEXE\u6587\u4ef6\u5728\u529f\u80fd\u5b9a\u4f4d\u548c\u6267\u884c\u65b9\u5f0f\u4e0a\u6709\u672c\u8d28\u533a\u522b\u3002 \u6f14\u8fdb\u5386\u7a0b\uff1a\u4eceDOS\u65f6\u4ee3\u7684\u9759\u6001\u94fe\u63a5\u56f0\u5883\uff0c\u5230Windows 95\u5f15\u5165\u6210\u719f\u7684DLL\u673a\u5236\uff0c\u518d\u5230.NET\u6846\u67b6\u4e0b\u7684\u6258\u7ba1DLL\uff0cDLL\u6280\u672f\u4e0d\u65ad\u6f14\u8fdb\uff0c\u5df2\u6210\u4e3aWindows\u751f\u6001\u7684\u6838\u5fc3\u652f\u67f1\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/47143.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-29T22:31:48+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"21 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/47143.html","url":"https:\/\/www.wsisp.com\/helps\/47143.html","name":"Windows-\u52a8\u6001\u94fe\u63a5\u5e93Dynamic Link Library\uff08.dll\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-29T22:31:48+00:00","dateModified":"2025-07-29T22:31:48+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/47143.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/47143.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/47143.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Windows---\u52a8\u6001\u94fe\u63a5\u5e93Dynamic Link Library\uff08.dll\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/47143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=47143"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/47143\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=47143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=47143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=47143"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=47143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}