Analysis on calling Visual C ++ DLL by C ++ Builder

Source: Internet
Author: User

Using C ++ Builder to call the DLL created by Visual C ++ DLL is not more difficult than calling the DLL built by C ++ Builder. First, borland and Microsoft use the COFF library format in different Visual C ++ formats in OBJ and import/export files, while Borland uses the OMF format.

This means that you cannot add a Microsoft-generated import database to the C ++ Builder project. Thanks to Borland IMPLIB, a utility that overcomes the differences in file formats.
The two products have different connection names (linker name.

This is the main obstacle for C ++ Builder to call Visual C ++ DLL. Each function in DLL or OBJ has a connection name. The connector uses the connection name to resolve during the connection) declares the prototype function. If the connector cannot find a function that is considered to be the connection name required by the program, it will generate an unresolved external error ).

Borland and Microsoft have different function connection names in the following two aspects:
1-Visual C ++ sometimes modifies the exported _ stdcall function.
2-Borland C ++ Builder considers it as the _ cdecl function when introducing this modified function.

So why is this important? Take the difference #1 _ stdcall call habits as an example. If you create a DLL using Visual C ++, it contains a _ stdcall modified function called MyFunction (), and Visual C ++ will give the function a connection name, is _ MyFunction @ 4. When the Borland connector tries to solve the problem of calling and constructing this function, it considers it to look for a function named MyFunction. Because Visual C ++ DLL does not include a function called MyFunction, Borland connector reports an unsolved external error and is aware that no function is found.

The methods to solve these three problems depend on the Visual C ++ DLL compilation method. I divided the entire process into two steps.
Step 2: Identify the call habits used in Visual C ++ DLL. In order to combat naming conventions, you must first determine the call habits used by functions in the DLL. You can check the DLL header file. The function prototype in the DLL header file is as follows:

Step 2: Check the connection name in the DLL. If the call habit of using _ stdcall is displayed in step 3, you need to further check the DLL, determine the naming conventions used When Visual C ++ creates it. By default, Visual C ++ modifies the _ stdcall function, but if programmers who write this DLL add a DEF file in their project, they can block the name modification. If the supplier does not use the DEF file, your trade unions are a little complicated.
The command line tool TDUMP allows you to check the connection name of the DLL export function. To call the TDUMP command for DLL.

TDUMP can report a lot of DLL information. We are only interested in DLL export functions. -The ee Command Option indicates that TDUMP only lists export information. The-m switch tells TDUMP to display data in the original format of the DLL function. Without the-m switch, TDUMP will try to convert the modified function into a readable format. If the DLL is large, you should redirect the output of TDUMP to a file through the append> MYDLL. LST ).

TDUMP is the test DLL output for source program list A and B as follows:

 
 
  1. bo Dump Version 5.0.16.4 Copyright (c) 1988, 1998 Borland International  
  2. Display of File DLL.DLL  
  3. EXPORT ord:0000='CdeclFunction' 
  4. EXPORT ord:0002='UnknownFunction' 
  5. EXPORT ord:0001='_StdCallFunction@4' 

Note the prefix underline and suffix @ 4 on the _ stdcall function. _ Cdecl and functions that do not specify the call method do not have any modifiers. If the DEF file is included in compile all C ++ DLL compilation, the modifier on the _ stdcall function will not appear.

  1. Differences between standard input implementation methods in C and C ++
  2. How does the C ++ compiler allocate storage space for Const constants?
  3. Basic Conception and method of C ++ Class Library Design
  4. Several Methods for converting C ++ Language
  5. How to better compile C ++ code

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.