VC creates DLL and C ++ builder call Process

Source: Internet
Author: User

VC creates DLL and C ++ builder call Process

In fact, I have done this for n times in my work, but I have forgotten how to do it every time I use it (I have a bad memory ), every time you want to create a DLL, you have to go online again to find an example and re-debug it, which is time-consuming and laborious. This time, I am determined to write down the entire process:

1. Create a DLL project named dllabc in VC, and the others will be OK by default.

2. Add the declaration in the header file dllabc. h:

Extern "C"

{

Int export _ stdcall add (int x, int y );

}

Add is the function name, and the operation of X + Y is completed.

3. Add the function content to the dllabc. cpp file:

Extern "C"

Int export _ stdcall add (int x, int y) // a function for completing addition operations

{

Return X + Y;

}

4. Add "add" to the file "dllabc. Def" with the same function name! I have spent a lot of time here.

5. Configure the release mode in VC and generate the DLL file.

6. The generated DLL file cannot be directly used in C ++ builder. to generate the Lib file, although the Lib file is also generated in VC, the format is different from that of C ++ builder and cannot be used. Use a tool named implib.exe for conversion. This file is installed on C ++ builder machines. You can search for it. If you cannot find one, download it online.

7. Copy the generated dllabc. dll and implib. EXE files to the same directory, such as C:/, so that they can be operated in DOS.

8. Go to DoS (I believe everyone will do it) and enter the following in C:

Implib dllabc. Lib dllabc. dll press ENTER

The generated dllabc. Lib is what we need.

IX. Copy the three files: dllabc. Lib (generated by implib), dllabc. dll, and dllabc. H to the C ++ builder project folder. Create a C ++ builder project, add a button control button1 and a text control edit1 to the form, and load dllabc. Lib in the C ++ builder project:

10. Add dllabc. H to the header file unit. H of the project.

11. An error occurred after generation: It appears in dllabc. h.

I thought for a moment, it turns out that this is the VC header file, and there are too many code charges (this is why I don't like Vc). It cannot be used in CBC. After deletion, only the statement is left:

12. Generate again without errors. Add the code in button1:

Void _ fastcall tform1: button1click (tobject * sender)

{

Int;

A = add (2, 4 );

Edit1-> text =;

}

Generate an executable file and run OK.

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.