⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcb 编写 dll 终极手册.htm

📁 我在网上收集的一些有关vcDLL编程的文章。
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 11">
<meta name=Originator content="Microsoft Word 11">
<link rel=File-List href="BCB%20编写%20DLL%20终极手册.files/filelist.xml">
<link rel=Edit-Time-Data href="BCB%20编写%20DLL%20终极手册.files/editdata.mso">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>BCB 编写 DLL 终极手册</title>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>pop</o:Author>
  <o:LastAuthor>pop</o:LastAuthor>
  <o:Revision>1</o:Revision>
  <o:TotalTime>0</o:TotalTime>
  <o:Created>2006-04-11T12:44:00Z</o:Created>
  <o:LastSaved>2006-04-11T12:44:00Z</o:LastSaved>
  <o:Pages>1</o:Pages>
  <o:Words>1281</o:Words>
  <o:Characters>7308</o:Characters>
  <o:Company>baodi</o:Company>
  <o:Lines>60</o:Lines>
  <o:Paragraphs>17</o:Paragraphs>
  <o:CharactersWithSpaces>8572</o:CharactersWithSpaces>
  <o:Version>11.5606</o:Version>
 </o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:PunctuationKerning/>
  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
  <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:Compatibility>
   <w:SpaceForUL/>
   <w:BalanceSingleByteDoubleByteWidth/>
   <w:DoNotLeaveBackslashAlone/>
   <w:ULTrailSpace/>
   <w:DoNotExpandShiftReturn/>
   <w:AdjustLineHeightInTable/>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" LatentStyleCount="156">
 </w:LatentStyles>
</xml><![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:宋体;
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-alt:SimSun;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
	{font-family:"\@宋体";
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0cm;
	margin-bottom:.0001pt;
	text-align:justify;
	text-justify:inter-ideograph;
	mso-pagination:none;
	font-size:10.5pt;
	mso-bidi-font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:宋体;
	mso-font-kerning:1.0pt;}
 /* Page Definitions */
 @page
	{mso-page-border-surround-header:no;
	mso-page-border-surround-footer:no;}
@page Section1
	{size:595.3pt 841.9pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;
	mso-header-margin:42.55pt;
	mso-footer-margin:49.6pt;
	mso-paper-source:0;
	layout-grid:15.6pt;}
div.Section1
	{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
	{mso-style-name:普通表格;
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
	mso-para-margin:0cm;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";
	mso-ansi-language:#0400;
	mso-fareast-language:#0400;
	mso-bidi-language:#0400;}
</style>
<![endif]-->
</head>

<body lang=ZH-CN style='tab-interval:21.0pt;text-justify-trim:punctuation'>

<div class=Section1 style='layout-grid:15.6pt'>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width="100%"
 style='width:100.0%;mso-cellspacing:0cm;mso-padding-alt:0cm 0cm 0cm 0cm'>
 <tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;height:30.0pt'>
  <td style='padding:0cm 0cm 0cm 0cm;height:30.0pt'>
  <p class=MsoNormal align=center style='text-align:center;mso-pagination:widow-orphan'><b><span
  lang=EN-US style='font-size:12.0pt;font-family:宋体;mso-bidi-font-family:宋体;
  mso-font-kerning:0pt'>BCB </span></b><b><span style='font-size:12.0pt;
  font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:0pt'>编写<span
  lang=EN-US> DLL </span>终极手册</span></b><span lang=EN-US style='font-size:9.0pt;
  font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:0pt'><o:p></o:p></span></p>
  </td>
 </tr>
 <tr style='mso-yfti-irow:1;mso-yfti-lastrow:yes;height:18.75pt'>
  <td style='border:none;border-bottom:solid windowtext 1.5pt;padding:0cm 0cm 0cm 0cm;
  height:18.75pt'>
  <p class=MsoNormal align=center style='text-align:center;mso-pagination:widow-orphan'><span
  style='font-size:9.0pt;font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:
  0pt'>【文章出处:转载】<span lang=EN-US>&nbsp;</span>【作者:未知】<span lang=EN-US>&nbsp;</span>【发布时间:<span
  lang=EN-US>2005-01-25</span>】<span lang=EN-US>&nbsp;</span>【查看: <span
  lang=EN-US><script language="JavaScript"  src="/php/count.php?artID=10756&view=yes">
  </script>19</span>次】 <span lang=EN-US><o:p></o:p></span></span></p>
  </td>
 </tr>
</table>

<p class=MsoNormal align=left style='text-align:left;mso-pagination:widow-orphan'><span
lang=EN-US style='font-size:9.0pt;font-family:宋体;mso-bidi-font-family:宋体;
display:none;mso-hide:all;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>

<div align=center>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width="96%"
 style='width:96.0%;mso-cellspacing:0cm;mso-padding-alt:0cm 0cm 0cm 0cm'>
 <tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;height:3.0pt'>
  <td colspan=3 style='padding:0cm 0cm 0cm 0cm;height:3.0pt'>
  <p class=MsoNormal align=left style='text-align:left;mso-pagination:widow-orphan'><span
  lang=EN-US style='font-size:3.0pt;mso-bidi-font-size:9.0pt;font-family:宋体;
  mso-bidi-font-family:宋体;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>
  </td>
 </tr>
 <tr style='mso-yfti-irow:1;mso-yfti-lastrow:yes'>
  <td valign=top style='padding:0cm 0cm 0cm 0cm' id=fontzoom>
  <p class=MsoNormal align=left style='text-align:left;line-height:15.0pt;
  mso-pagination:widow-orphan'><span lang=EN-US style='font-size:10.0pt;
  font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>
  <p class=MsoNormal align=left style='text-align:left;line-height:15.0pt;
  mso-pagination:widow-orphan'><span style='font-size:10.0pt;font-family:宋体;
  mso-bidi-font-family:宋体;mso-font-kerning:0pt'>由于现在比较多的网友老是在<span lang=EN-US>
  CSDN </span>上询问关于<span lang=EN-US> BCB </span>编写<span lang=EN-US> DLL </span>的问题,我编写了这篇文章抛砖引玉<span
  lang=EN-US> <br>
  <br>
  </span>一<span lang=EN-US>. </span>编写<span lang=EN-US> DLL <br>
  File/New/Dll </span>生成<span lang=EN-US> Dll </span>的向导,然后可以添加导出函数和导出类<span
  lang=EN-US> <br>
  </span>导出函数:<span lang=EN-US>extern &quot;C&quot; __declspec(dllexport)
  ExportType FunctionName(Parameter) <br>
  </span>导出类:<span lang=EN-US>class __declspec(dllexport) ExportType
  ClassName{...} <br>
  </span>例子:<span lang=EN-US>(</span>说明:只是生成了一个<span lang=EN-US> DLL.dll ) <br>
  <br>
  #include &quot;DllForm.h&quot; // TDllFrm </span>定义<span lang=EN-US> <br>
  <br>
  USERES(&quot;Dll.res&quot;); <br>
  USEFORM(&quot;DllForm.cpp&quot;, DllFrm); <br>
  <br>
  class __declspec(dllexport) __stdcall MyDllClass { //</span>导出类<span
  lang=EN-US> <br>
  </span> <span lang=EN-US>public: <br>
  </span> <span lang=EN-US> MyDllClass(); <br>
  </span> <span lang=EN-US> void CreateAForm(); <br>
  </span> <span lang=EN-US> TDllFrm* DllMyForm; <br>
  }; <br>
  <br>
  TDllFrm* DllMyForm2; <br>
  extern &quot;C&quot; __declspec(dllexport) __stdcall void CreateFromFunct();//</span>导出函数<span
  lang=EN-US> <br>
  <br>
  //---------------------------------------------------------------------------
  <br>
  int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*) <br>
  { <br>
  </span> <span lang=EN-US>return 1; <br>
  } <br>
  //---------------------------------------------------------------------------
  <br>
  <br>
  MyDllClass::MyDllClass() <br>
  { <br>
  } <br>
  <br>
  void MyDllClass::CreateAForm() <br>
  { <br>
  </span> <span lang=EN-US>DllMyForm = new TDllFrm(Application); <br>
  </span> <span lang=EN-US>DllMyForm-&gt;Show(); <br>
  } <br>
  //---------------------------------------------------------------------------
  <br>
  void __stdcall CreateFromFunct() <br>
  { <br>
  </span> <span lang=EN-US>DllMyForm2 = new TDllFrm(Application); <br>
  </span> <span lang=EN-US>DllMyForm2-&gt;Show(); <br>
  } <br>
  <br>
  <br>
  </span>二<span lang=EN-US>. </span>静态调用<span lang=EN-US> DLL <br>
  </span>使用<span lang=EN-US> $BCB path\Bin\implib.exe </span>生成<span
  lang=EN-US> Lib </span>文件,加入到工程文件中<span lang=EN-US> <br>
  </span>将该文件拷贝到当前目录,使用<span lang=EN-US> implib MyDll.lib MyDll.dll </span>生成<span
  lang=EN-US> <br>
  // Unit1.h // TForm1 </span>定义<span lang=EN-US> <br>
  #include &quot;DllForm.h&quot; // TDllFrm </span>定义<span lang=EN-US> <br>
  //---------------------------------------------------------------------------
  <br>
  <br>
  __declspec(dllimport) class __stdcall MyDllClass { <br>
  </span> <span lang=EN-US>public: <br>
  </span>  <span lang=EN-US>MyDllClass(); <br>
  </span>  <span lang=EN-US>void CreateAForm(); <br>
  </span>  <span lang=EN-US>TDllFrm* DllMyForm; <br>
  }; <br>
  extern &quot;C&quot; __declspec(dllimport) __stdcall void CreateFromFunct(); <br>
  <br>
  class TForm1 : public TForm{...} <br>
  <br>
  <br>
  // Unit1.cpp // TForm1 </span>实现<span lang=EN-US> <br>
  void __fastcall TForm1::Button1Click(TObject *Sender) <br>
  { // </span>导出类实现,导出类只能使用静态方式调用<span lang=EN-US> <br>
  </span> <span lang=EN-US>DllClass = new MyDllClass(); <br>
  </span> <span lang=EN-US>DllClass-&gt;CreateAForm();</span> <span lang=EN-US>
  <br>
  } <br>
  //---------------------------------------------------------------------------
  <br>
  void __fastcall TForm1::Button2Click(TObject *Sender) <br>
  { // </span>导出函数实现<span lang=EN-US> <br>
  </span> <span lang=EN-US>CreateFromFunct(); <br>
  } <br>
  //---------------------------------------------------------------------------
  <br>
  <br>
  void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &amp;Action) <br>
  { <br>
  </span> <span lang=EN-US>delete DllClass; <br>
  } <br>
  <br>
  </span>三<span lang=EN-US>. </span>动态调用<span lang=EN-US> DLL <br>
  // Unit1.h <br>
  class TForm1 : public TForm <br>
  { <br>
  ... <br>
  private: // User declarations <br>
  void (__stdcall *CreateFromFunct)(); <br>
  ... <br>
  } <br>
  <br>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -