Anda di halaman 1dari 2

#include "MDLL.

h"
Button1Click
{Edit1->Text=Code_Dec(Edit1->Text.c_str(),'A'); }

DLL: MDLL.cpp MDLL.h


#include <vcl.h>
#include <windows.h>
#pragma hdrstop #ifndef _MDLL_H
//-------------------------------- #define _MDLL_H

#pragma argsused #ifdef __DLL__


#include "MDLL.h" #define DLL_EI __declspec(dllexport)
int WINAPI DllEntr------------------------ #else
#define DLL_EI __declspec(dllimport)
char * Code_Dec(char *s, char Key) #endif
{ for (int i = 0; ; i++)
{ if (s[i] == '\0') break; extern "C" char * DLL_EI Code_Dec(char *s, char
s[i] = s[i] ^ Key; Key);
} return s;
} #endif

DLL :
1. ++biulder, File->Close All, .
2. File->New->Other-- New DLL Wizard (
DLL), ( ) ++, ,
<vcl.h> (
- ), ++ Style DLL DLL
Visual C++,

3. ,
(),
DLL ( MDLL.cpp).
4. int WINAPI DllEntr-----
, : #include "MDLL.h" .
5. File->New->Other-- New Header file
( MDLL.h).
6. , h.
7. , File->Save Project As ..
, , Project1 :
PMDLL.
8.
Project->Build MDLL. Done -> Build All, .. .
9. ,
.
10. ,
DLL: MDLL.h.
11. .lib,
8 . View->Project Manager
Add,
Library file (*.lib).
.
12. ,
.
: 11 , lib ,
Project->View Source.
, USEFORM("Unit1.cpp", Form1);
: USELIB("TMDLL.lib");
.

DLL :
1) 9
2) , .. File->New->Application;
3)
, .

4)
: -> (. .)
5)
.
:
private: // User declarations
// DLL
HINSTANCE dllInstance;
//

typedef char (__import * FType(char *,
char));
FType * C_D;
public:
6) :
void __fastcall TForm1::Button2Click(TObject void __fastcall
*Sender) TForm1::Button1Click(TObject
{// DLL *Sender)
dllInstance = LoadLibrary("PUMyDLL.dll"); {
if (dllInstance) if (C_D) Edit1->Text=C_D(Edit1-
// >Text.c_str(),'A');
C_D = (FType *)GetProcAddress(dllInstance, else
"_Code_Dec"); ShowMessage(" 'Code_Dec'
else ShowMessage(" !");
'UMyDLL'"); }
}
void __fastcall TForm1::Button3Click(TObject
*Sender)
{// DLL
FreeLibrary(dllInstance);
C_D=NULL;
}

Anda mungkin juga menyukai