开发者社区> 狂斩一条龙> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

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.

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
Microsoft Visual Studio 遇到了问题需要关闭
新年刚来Microsoft Visual Studio就找麻烦,debug的时候如果不打断点可以正常跑过,一打断点就崩溃,重启。报的问题是:Microsoft Visual Studio 遇到了问题需要关闭。
691 0
什么是Microsoft SharePoint 2010
什么是Microsoft SharePoint 2010? SharePoint是允许用户创建网站的微软平台。SharePoint 2010 是微软的第四代SharePoint产品,被称作SharePoint v4 或者是MOSS2010(Microsoft Office SharePoint Server 2010)。
512 0
Microsoft Visual Studio 2010的前世今生
N年前,江湖上流传着几个大佬的故事,他们说:Dev-C++灵活又小巧,C++ Builder开发效率高;Turbo C是万人迷,Visual Studio的资格老。可如今,江湖上只剩下最后一个大佬Visual Studio了,其他几位不是支持者渐少,不成气候,就是转投他人怀抱,中道衰落,让人难免生出几分遗憾。
1043 0
Two weeks in Microsoft
I've been working in Microsoft in these two weeks for a POC of Knowledge Management feature with SP2010 for China Mobile.
495 0
+关注
狂斩一条龙
惯用c++,在windows平台做应用开发和底层研究,并对ua语言有深入的了解
文章
问答
文章排行榜
最热
最新
相关电子书
更多
Infecting-The-Enterprise-Abusing-Office365-Powershell-For-Covert-C2
立即下载
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载