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

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
    [email protected]                        =_Add               @1 

New export section
EXPORTS
   [email protected] 

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.

时间: 2024-11-10 19:52:19

Using Microsoft Visual C++ DLLs with C++Builder的相关文章

Microsoft Visual Studio正在等待操作完成

在编译项目的时候,有时会遇到 Microsoft Visual Studio正忙,结果就是半天没反应,要等待很长时间才能编译完成,在网上查了一下资料,微软官方是这样解释的: 阻止某些 devenv.exe 进程的防病毒软件也可能导致此错误. 产品中的几项功能使用脚本,而这些脚本可能会被防病毒软件阻止. 有关的信息,请参见位于 http://support.microsoft.com/default.aspx?scid=kb;zh-cn;306905&Product=vsnet 上的“PRB: V

安装python 第三方库遇到的安装问题 microsoft visual studio c++ 10.0 is required,Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?

问题一: microsoft visual studio c++ 10.0 is required 安装scrapy时候出现需要vc c++ 10,有时安装其他也会有. 解决方法:安装vc 2010,安装过2017无效,安装过程也不一样. 问题二: 安装好,出现Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed? 解决办法: 1.pip install wheel 2. 到http://

Microsoft Visual Studio 10.0执行WinPcap获取网络设配器的代码

WinPcap是一个基于Win32平台的,用于捕获网络数据包并进行分析的开源库. 大多数网络应用程序通过被广泛使用的操作系统元件来访问网络,比如sockets.  这是一种简单的实现方式,因为操作系统已经妥善处理了底层具体实现细节(比如协议处理,封装数据包等等),并且提供了一个与读写文件类似的,令人熟悉的接口. 然而,有些时候,这种"简单的方式"并不能满足任务的需求,因为有些应用程序需要直接访问网络中的数据包.也就是说,那些应用程序需要访问原始数据包,即没有被操作系统利用网络协议处理过

Microsoft Visual Studio 2015 下载、注册、安装过程、功能列表、问题解决

PS:请看看回复.可能会有文章里没有提到的问题.也许会对你有帮助哦~ VS2015正式版出了,虽然没有Ultimate旗舰版,不过也是好激动的说.哈哈.可能有的小伙伴,由于工作环境不允许.或者害怕有什么问题.所以不敢安装vs2015.只能眼巴巴地干瞅着. 因此,我决定,冒一次重装系统的风险,试着安装一下,正好也试试什么序列号能用.希望这次牺牲能值得~~呵呵. 下载地址:Microsoft Visual Studio 2015 全版本+离线MSDN+全部插件 赶紧下载,打开,发现VS2015对安装

(转)Windows下pip安装包报错:Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat

刚在机器上windows环境下装上pip方便以后安装包的时候使用,谁知道第一次使用pip安装asyncio的时候就报错. 在Windows7x64下使用pip安装包的时候提示报错:Microsoft Visual C++ 9.0 is required  (Unable to find vcvarsall.bat) 环境:windows7 x64 ,python2.7 ,VS2012 原因:windows下使用pip安装包的时候需要机器装有vs2008,VS2012还不行,如果不想装VS2008

Microsoft Visual Studio 2015 python 安装 mysql-python 出错解决

Microsoft Visual Studio 2015 安装 python 连接包 mysql-python出错   第一种 pip安装方式 安装Microsoft Visual C++ Compiler for Python 2.7 安装后错误改变   无用 _mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory   暂时未解决 第二种方式eas

Microsoft Visual Studio International Pack 1.0 SR1--关于汉字转拼音

Microsoft Visual Studio International Pack 1.0 SR1————微软的一个类库 地址:http://www.microsoft.com/zh-cn/download/details.aspx?id=15251 Visual Studio International Pack 包含一组类库,该类库扩展了.NET Framework对全球化软件开发的支持.使用该类库提供的类,.NET 开发人员可以更方便的创建支持多文化多语言的软件应用.SR1 包含对 Ja

Microsoft Visual Studio 正忙

简介:Microsoft Visual Studio 正忙,Microsoft Visual Studio 正在等待内部操作完成.如果经常在正常使用的情况下遇到此延迟, 请向Microsoft报告此情况. 问题效果图: --------------------------------------------------------------------------------------------------------------------------------------------

获取设备列表(Microsoft Visual Studio 2010)

通常,编写基于WinPcap应用程序的第一件事情,就是获得已连接的网络适配器列表.libpcap和WinPcap都提供了 pcap_findalldevs_ex() 函数来实现这个功能: 这个函数返回一个 pcap_if 结构的链表, 每个这样的结构都包含了一个适配器的详细信息.值得注意的是,数据域 name 和 description 表示一个适配器名称和一个可以让人们理解的描述. 我们使用Microsoft Visual Studio 2010编译工具编译程序,中WinPcap文档中模块下找