1. Create:
Use BCB
File | new creates a new DLL project, saves the file BCB, and generates a DLL program framework.
1. the dllentrypoint function is an entry method. If a user is called when the DLL is initialized or deregistered by the system, it is used to write the DLL initialization program and uninstall the program. Parameter: hinst is used to indicate the base address of the DLL; reason is used to indicate the DLL call method. It is used to distinguish the call, creation, and uninstallation of a DLL by a single thread in multiple threads;
2. Add the DLL process and function to the program;
3. Use dllimport to describe the exit;
The example program is as follows:
# Include
# Pragma hdrstop
Extern "C" _ declspec (dllexport) int
Test ();
Int winapi dllentrypoint (hinstance hinst, unsigned long
Reason, void *)
{
Return 1;
}
Int test ()
{
Return 3;
}
Note: The call Methods _ cdecl, _ Pascal, and,
_ Fastcall, _ stdcall, the default method in BCB is _ cdecl (do not write). If compatibility is considered, the _ stdcall declaration method is:
Extern
"C" _ declspec (dllexport) int _ stdcall
Test ();
For the process and function, change:
Int _ stdcall
Test ()
Ii. Use DLL
There are two methods to use DLL in BCB:
1. Use static call Method
First, you must add the Import
Library), open the project, use BCB View | Project
Open the project list and add the interface library (*. Lib) to the project ).
Add the interface declaration to the header file.
The example program is as follows:
// Define in include file
Extern "C" _ declspec (dllimport) int _ cdecl
Test ();
// Use function in main program
Int
I;
I = test ();
Note:
(1) dynamically linked Library call process and function call Method
It is not written as _ cdecl in the same way as it was created. Other statements must be declared.
(2) The DLL created by BCB has a corresponding input interface library (Import
Library). If there is only a DLL without a library, use the implib tool of BCB to generate: implib XXX. Lib XXX. dll. In addition, use: tlib.
Xxx. Lib, XXX. lst
This method is used to generate a list of DLL internal functions that are not publicly known in windows.
2. Dynamic call Method
Use Windows for dynamic calling
API
Loadlibrary () and getprocaddress () in To Call The dll library and point out the function location in the library. This method is more common.
The example program is as follows:
Caption = inttostr (DDD ());
Freelibrary (dd );
3. Note:
Pay attention to setting the project when compiling the link during DLL Creation
Options.
Packages Tag: Remove builder with Runtime
Packages check box.
Linker label: remove the use dynamic RTL check box.
Otherwise, the created DLL requires runtime.
Packages or Runtime Library.
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