BCB Writing DLL Ultimate Handbook

Source: Internet
Author: User
Tags export class

I. Writing a DLL

File/new/dll The wizard that generates the DLL, and then you can add export functions and export classes

Export function: extern "C" __declspec (dllexport) exporttype functionname (Parameter)

Export class: Class __declspec (dllexport) exporttype classname{...}

Example: (Note: Only a DLL.dll was generated)

#include "DllForm.h"//TDLLFRM definition
useres ("Dll.res");
Useform ("DllForm.cpp", dllfrm);
Class __declspec (dllexport) __stdcall Mydllclass {//Export class
Public:
Mydllclass ();
void Createaform ();
tdllfrm* Dllmyform;
};
tdllfrm* DllMyForm2;
extern "C" __declspec (dllexport) __stdcall void createfromfunct ();//Export function
//--------------------------------- ------------------------------------------
int WINAPI DllEntryPoint (hinstance hinst, unsigned long reason, void*)
{
return 1;
}
//---------------------------------------------------------------------------
Mydllclass::mydllclass ()
{
}
void Mydllclass::createaform ()
{
Dllmyform = new Tdllfrm (application);
Dllmyform->show ();
}
//---------------------------------------------------------------------------
void __stdcall Createfromfunct ()
{
DllMyForm2 = new Tdllfrm (application);
Dllmyform2->show ();
}

Two. Static Call DLL

Use $BCB path\bin\implib.exe to generate Lib files and add them to the project file

Copy the file to the current directory, using the Implib MyDll.lib MyDll.dll build

// Unit1.h // TForm1 定义
#include "DllForm.h" // TDllFrm 定义
//---------------------------------------------------------------------------
__declspec(dllimport) class __stdcall MyDllClass {
public:
MyDllClass();
void CreateAForm();
TDllFrm* DllMyForm;
};
extern "C" __declspec(dllimport) __stdcall void CreateFromFunct();
class TForm1 : public TForm{...}
// Unit1.cpp // TForm1 实现
void __fastcall TForm1::Button1Click(TObject *Sender)
{ // 导出类实现,导出类只能使用静态方式调用
DllClass = new MyDllClass();
DllClass->CreateAForm();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{ // 导出函数实现
CreateFromFunct();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete DllClass;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.