(File / New / DLL). , :
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*) { return 1; }, DLL dll String.
DLL __export __import . C++ Builder __delspec() dllexport dllimport . , _delspec(dllexport) , _delspec(dllimport) , . : :
#if defined(BUILD_DLL)# define DLL_EXP __declspec(dllexport)#else# if defined(BUILD_APP)# define DLL_EXP __declspec(dllimport)# else# define DLL_EXP# endif#endifDLL #define BUILD_DLL, __declspec(dllexport) DLL_EXP. #define BUILD_APP, DLL.
DLL: P.cpp
//---------------------------------------------------------------------------#define BUILD_DLL#include #include "p.h"#pragma hdrstop //---------------------------------------------------------------------------// Important note about DLL memory management when your DLL uses the// static version of the RunTime Library://// If your DLL exports any functions that pass String objects (or structs/// classes containing nested Strings) as parameter or function results,// you will need to add the library MEMMGR.LIB to both the DLL project and// any other projects that use the DLL. You will also need to use MEMMGR.LIB// if any other projects which use the DLL will be perfomring new or delete// operations on any non-TObject-derived classes which are exported from the// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,// the file BORLNDMM.DLL should be deployed along with your DLL.// To avoid using BORLNDMM.DLL, pass string information using "char *" or// ShortString parameters.//// If your DLL uses the dynamic version of the RTL, you do not need to// explicitly add MEMMGR.LIB as this will be done implicitly for you//-------------------------------------------------------------------------int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*) { return 1; } //------------------------------------------------------------------------- void Message(char *s) { i=10; Application->MessageBox(s,"From DLL",IDOK); }P.h
#if defined(BUILD_DLL)# define DLL_EXP __declspec(dllexport)#else# if defined(BUILD_APP)# define DLL_EXP __declspec(dllimport)# else# define DLL_EXP# endif#endif DLL_EXP void Message(char *s);DLL_EXP int i;.
|
|
Run (). . (File / New Application) OnClick. :
//---------------------------------------------------------------------------#include #define BUILD_APP#pragma hdrstop#include "p.h"#include "Unit1.h"#include //---------------------------------------------------------------------------#pragma package(smart_init)#pragma resource "*.dfm"TForm1 *Form1;//-------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner) { } //-------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender) { char c[10]; Message("roma"); for(; i>0;i--) { sprintf(c,"Example %d",i); Application->MessageBox("Example of using DLL variable",(char*)c,IDOK); }} //-------------------------------------------------------------------------. . .lib DLL( , ADD). .
, , DLL : DLL, .lib.