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.

最新文章

  1. 如何在一个div标签里显示出另一个网页? <iframe src=" http://www.baidu.com " width="800px" height="200px" scrolling="no" frameborder="0"> </iframe>
  2. C#-INotifyPropertyChanged(解决数据绑定的界面刷新问题)
  3. GP服务将矢量数据加入到栅格数据中的方法
  4. BZOJ 1208: [HNOI2004]宠物收养所
  5. RunTime(运行时机制)
  6. DW 图片不显示的情况 ———网页只显示字不显示图片的情况 目录下的图片名被改动不显示图片的情况
  7. Android AudioPolicyService和AudioPolicyManager
  8. Android中Activity.this,getApplicationContext(),getBaseContext()和this详解
  9. Android-Animation (1) 视图动画
  10. C语言实验一(3)
  11. 数据结构与算法之PHP排序算法(归并排序)
  12. 第六章:声明式服务调用:Spring Cloud Feign
  13. Hexo 的next主题下添加网易云音乐作BGM
  14. Efficiency optimizing
  15. hdu 5826 physics 物理题
  16. python with 语句妙用
  17. MSSQL中IN是否用索引.....[转]
  18. warning,C4996,sprintf,deprecated,C4996,strcpy,C4996,strcat
  19. 转载-lvs-dr模式+keepalived双机
  20. 关于&$地址传递的练习

热门文章

  1. java四大名著及idea常用插件
  2. Exchanger实现线程间数据交换
  3. <统计学>统计学开篇
  4. mousedown、mouseup、click事件之间的关系及执行顺序
  5. linux 下mongo 基础配置
  6. [SQL] - Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 问题之解决
  7. 题解 Luogu P1110 【[ZJOI2007]报表统计】
  8. 第1章:LeetCode--基础部分
  9. linux 列出本文件下的目录
  10. CH01-ZYNQ修炼秘籍-LINUX篇-虚拟机环境搭建