Using Microsoft Visual C + + DLLs with C++builder

Source: Internet
Author: User

Using Microsoft Visual C + + DLLs with C++builder

as powerful as C++builder is, the majority of DLLs developed and used within the software community are Built using Visual C + +. Therefore, chances is you'll need to interface your C++builder code with a Visual C + + DLL. Again, there is the ways for a DLL to attach to an application. Either it can be loaded in dynamically, or it can be loaded in statically if the LIB file associated to the DLL is linked At compile time. If The Lib file is a Microsoft LIB file, the DLL won ' t being able to load. The reason is because of the compatibility issues between the LIB file format for Visual C + + and C++builder. Both Vendors use different exporting conventions. Microsoft supports the Common Object Format File (COFF), whereas Borland uses the object Model format (OMF). Fortunately, there is a-to-create Borland OMF import library file that represents a Microsoft built DLL.

To create a Borland compatible . lib file for a Visual C + + DLL, you can use the Coff2omf command-line tool from Bo Rland, which resides in the Bin folder under C++builder. Coff2omf takes, arguments:the first is the source library's filename; And the second is the destination ' s filename.

In this example, COFF2OMF would generate a new OMF library file called mydll_bor.lib. Within your C++builder project, be-sure to-link using this mydll_bor.lib file as part of the project file listing .

NOTE

The coff2omf utility only works in Lib files with a simple exported C functions. If C + + classes is exported, it won't work.

If this doesn ' t work, you need to find out how the functions is being exported and give them an alias that c++builder wil L like. To does this, first you should use Impdef.exe to create a definition file (or . def file), which enables yo U to view all the exported functions ' names and ordinal numbers. Next, modify the exported functions in the . def file, and the function looks like this:

Old export sections exports     [email protected]                        =_add               @1 New Export Section Exports    

After you have made the changes to the library, save the . def file. Now you can use the Implib.exe on the This file to create a new library file, the C++builder should like. Implib.exe also takes, parameters:the destination and the source. For example

Because You now has a library in c++builder style, you should is able to include it in your project and use the DLL and C0>.lib.

See the vcppproject folder on the CD-ROM that is accompanies this book for the Complete C++builder project CALLV CPPDLL.BPR. This uses the Visual C + + DLL mentioned previously.

Using Microsoft Visual C + + DLLs with C++builder

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.