DLL . , DLL . .
1. / . MyDLL.dll. (.10.5) .
.10.5 DLL
.10.6
2. . . . / , Project1.exe, (.10.6).
3. / UTestDLL, PTestDLL.
.10.7 DLL
4. / TESTDLL. / DLL PTestDLL.exe, (.10.7).
5. Edit1 Button1 (.10.8).
) )
.10.8 DLL: ()
()
:
Edit1->Text = Code_Dec(Edit1->Text.c_str(),A);
, Edit1, Code_Dec Edit1.
6. #pragma hdrstop , :
#include UMyDLL.h
UTestDLL.h:
//---------------------------------------------------------------------------
#ifndef UTestDLLH
#define UTestDLLH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1: public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TButton *Button1;
void __fastcall Button1Click(Tobject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
UTestDLL.cpp:
|
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include UMyDLL.h
#include UTestDLL.h
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource *.dfm
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(Tcomponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(Tobject *Sender)
{
Edit1->Text = Code_Dec(Edit1->Text.c_str(),A);
}
//---------------------------------------------------------------------------
7. .lib, . , PTestDLL.exe (.10.9).
.10.9
8. / . (*.lib) MyDLL.lib. (.10.10). .
9. , . .10.8.
.10.10
10. . . . .
11. / ( , DLL) UTestDLL2, PTestDLL2. , (.10.11).
.10.11 - DLL,
PTestDLL.exe PTestDLL2.exe
.10.12 DLL
12. Edit1 Button1,2,3 (.10.12). ( BLoad) DLL, ( BFree) , / ( Button1) , .
13. (. ).
//---------------------------------------------------------------------------
#ifndef UTestDLL2H
#define UTestDLL2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm2: public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TButton *Button1;
TButton *BLoad;
TButton *BFree;
void __fastcall BLoadClick(TObject *Sender);
void __fastcall BFreeClick(TObject *Sender);
|
|
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
// DLL
HINSTANCE dllInstance;
//
typedef char* (__import FType(char *, char));
FType * C_D;
public: // User declarations
__fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
dllInstance DLL. FType Code_Dec, . C_D .
14. :
#include <vcl.h>
#pragma hdrstop
#include "UTestDLL2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::BLoadClick(TObject *Sender)
{
// DLL
dllInstance = LoadLibrary("MyDLL.dll");
if(dllInstance)
//
C_D = (FType *)GetProcAddress(dllInstance, "_Code_Dec");
else ShowMessage( 'MyDLL.dll');
}
//---------------------------------------------------------------------------
void __fastcall TForm2::BFreeClick(TObject *Sender)
{
// DLL
FreeLibrary(dllInstance);
C_D = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
if (C_D)
Edit1->Text = C_D(Edit1->Text.c_str(),'A');
else ShowMessage(
" 'Code_Dec' 'MyDLL.dll' ");
}
//---------------------------------------------------------------------------
BLoadClick LoadLibrary. , dllInstance NULL. 'MyDLL.dll'. , GetProcAddress C_D .
Button1Click C_D. NULL (, , , Button1Click , ), .
BFreeClick FreeLibrary DLL C_D.
15. , (.10.12).
16. , .
1. DLL?
2. DLL. ?
3. DLL . ?
4. ?
5. ?
6. ?
7. DLL.
8. DLL?
9. ?
10. ?
|
|
11. ?
12. DLL?
13. DLL?
14. ? .