Using Microsoft Visual C++ DLLs with C++Builder

简介: 摘自《Borland C++BuilderT 6 Developer's Guide》  一书 Using Microsoft Visual C++ DLLs with C++Builder As powerful as C++Builder is, the majority of DLLs d...

摘自《Borland C++BuilderT 6 Developer's Guide》  一书

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 are you will need to interface your C++Builder code with a Visual C++ DLL. Again, there are two 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 that LIB file is a Microsoft LIB file, the DLL won't be 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 way to create a 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 Borland, which resides in the Bin folder under C++Builder. COFF2OMF takes two arguments: the first is the source library's filename; and the second is the destination's filename.

Coff2Omf MyDll.lib MyDll_bor.lib 

In this example, COFF2OMF will 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 on lib files with simple exported C functions. If C++ classes are exported, it will not work.

 

If this doesn't work, you need to find out how the functions are being exported and give them an alias that C++Builder will like. To do this, first you should use Impdef.exe to create a definition file (or .def file), which enables you to view all the exported functions' names and ordinal numbers. Next, modify the exported functions in the .def file, so the function looks like this:

Old export section 
EXPORTS 
    _Add@8                        =_Add               @1 

New export section 
EXPORTS 
   Add=_Add@8 

After you've made the changes to the library, save the .def file. Now you can use Implib.exe on this file to create a new library file that C++Builder should like. Implib.exe also takes two parameters: the destination and the source. For example

Implib MyDll.lib MyDll.def 

Because you now have a library in C++Builder style, you should be able to include it in your project and use the DLL and .lib.

See the VCppProject folder on the CD-ROM that accompanies this book for the complete C++Builder project CallVCppDll.bpr. This uses the Visual C++ DLL mentioned previously.

相关文章
|
6月前
|
编译器 开发工具 C++
【Python】已解决error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build
【Python】已解决error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build
3591 0
|
7月前
|
存储 分布式数据库 API
技术好文:VisualC++查看文件被哪个进程占用
技术好文:VisualC++查看文件被哪个进程占用
|
4月前
|
C++ 内存技术
[转]Visual C++内嵌swf文件并播放
[转]Visual C++内嵌swf文件并播放
|
5月前
|
安全 编译器 C++
Microsoft Visual C++ Redistributable的作用主要体现以及可以删除吗?
这些是Microsoft Visual C++不同版本的Redistributable安装包,用于32位系统,确保相关应用正常运行。它们提供C++运行时环境,简化部署流程,支持第三方库及框架,并确保应用兼容性。定期更新可修复问题并引入新功能。在空间有限或需解决程序冲突时可考虑删除,但需谨慎操作以防影响应用稳定性和兼容性。删除前请确认无应用依赖,并通过控制面板安全卸载。
304 1
Microsoft Visual C++ Redistributable的作用主要体现以及可以删除吗?
|
6月前
|
C++ Windows
FFmpeg开发笔记(三十九)给Visual Studio的C++工程集成FFmpeg
在Windows上使用Visual Studio 2022进行FFmpeg和SDL2集成开发,首先安装FFmpeg至E:\msys64\usr\local\ffmpeg,然后新建C++控制台项目。在项目属性中,添加FFmpeg和SDL2的头文件及库文件目录。接着配置链接器的附加依赖项,包括多个FFmpeg及SDL2的lib文件。在代码中引入FFmpeg的`av_log`函数输出"Hello World",编译并运行,若看到"Hello World",即表示集成成功。详细步骤可参考《FFmpeg开发实战:从零基础到短视频上线》。
259 0
FFmpeg开发笔记(三十九)给Visual Studio的C++工程集成FFmpeg
|
5月前
|
缓存 C++ Windows
Inno setup 脚本判断 Microsoft Visual C++ Redistributable 不同版本区别
Inno setup 脚本判断 Microsoft Visual C++ Redistributable 不同版本区别
|
5月前
|
编译器 C++ 开发者
Visual Studio属性表:在新项目中加入已配置好的C++库
通过以上步骤可以确保Visual Studio中新项目成功地加入了之前已配置好的C++库。这个过程帮助开发者有效地管理多个项目中共享的库文件,提升开发效率。
138 0
|
7月前
|
JSON 开发工具 C语言
编程入门(五)【Visual Studio Code安装与C/C++语言运行】
编程入门(五)【Visual Studio Code安装与C/C++语言运行】
777 0
|
8月前
|
C语言 C++ 开发者
LabVIEW调用C/C++ DLLs
LabVIEW调用C/C++ DLLs
138 0
|
2月前
|
存储 编译器 C语言
【c++丨STL】string类的使用
本文介绍了C++中`string`类的基本概念及其主要接口。`string`类在C++标准库中扮演着重要角色,它提供了比C语言中字符串处理函数更丰富、安全和便捷的功能。文章详细讲解了`string`类的构造函数、赋值运算符、容量管理接口、元素访问及遍历方法、字符串修改操作、字符串运算接口、常量成员和非成员函数等内容。通过实例演示了如何使用这些接口进行字符串的创建、修改、查找和比较等操作,帮助读者更好地理解和掌握`string`类的应用。
63 2