使用 Visual C++旧 Borland C 中的 DLL?
我必须支持使用旧的 Borland 编译器 (BC 5) 用 C 编写的旧应用程序。
不幸的是,我们使用的旧 TCP/IP 库开始显示出它的年龄,并且在 Vista 和 Windows 上出现问题。 Win7机器。
我有一个可用于 MS Visual C++ 的新函数库,我想用它来制作一个可以从 Borland C 调用的 DLL。
所以,我有两个问题: 1) 如何使 Visual C++ DLL 可从 Borland C 程序调用,以及 2)如果它是可调用的,如何从普通的旧C调用C++函数?
理想情况下,整个项目应转换为 Visual C,但有许多遗留功能将使该项目成为一项重大任务!我正在寻找一个快速补丁以使其存活更长时间:)
Steve
I've got to support an old app written in C using the old Borland Compiler (BC 5).
Unfortunately the old TCP/IP library that we'd used is starting to show it's age and is having problems with Vista & Win7 machines.
I have a new library of functions available for MS Visual C++, and I'd like to use that to make a DLL that would be callable from the Borland C.
So, I have 2 issues:
1) how to make a Visual C++ DLL callable from a Borland C program, and
2) if it is callable, how to call the C++ functions from plain old C?
Ideally, the entire project should be converted to Visual C, but there a lot of legacy features that'll make that project a major undertaking! I'm looking for a quick patch to keep it alive for a while longer :)
Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Visual C++ 编写一个 DLL,将其接口公开为 Windows STDCALL C 函数。 Windows API 函数的处理方式类似。您在界面中公开的那些函数将执行您需要在程序中替换的函数。在 DLL 内,放弃调用新的 MS VC++ 库。
因此,要获得可从 C 调用并使用 STDCALL 堆栈协议的函数,请执行以下操作:
extern "C" int __stdcall foo();
您还必须添加信息以从以下位置导出函数DLL。您可以在声明中显式地执行此操作,如下所示:
extern "C" __declspec(dllexport) int __stdcall foo();
但是您需要一个单独的头文件用于您的 BorlandC 代码(可能是有不同的语法来指定 DLL 导入部分和 STDCALL 部分)。在 Visual C++ 中,您在客户端中使用的声明类似于:
extern "C" __declspec(dllimport) int __stdcall foo();
Write a DLL using Visual C++ that exposes its interface as Windows STDCALL C functions. Windows API functions are done similarly. Those functions you expose in the interface will perform the functions you need to replace in your program. Inside the DLL, call the new MS VC++ library with abandon.
So to get a function that is callable from C and uses STDCALL stack protocol do something like this:
extern "C" int __stdcall foo();
you'll also have to add information to export the function from the DLL. You might do this explicitly in the declaration as such:
extern "C" __declspec(dllexport) int __stdcall foo();
But you'll need a separate header file for use in your BorlandC code (which probably has different syntax for specifying the DLL import part and the STDCALL part). In Visual C++ the declaration you'd use in the client would look something like:
extern "C" __declspec(dllimport) int __stdcall foo();
您可以使用 Borland 的 IMPLIB 实用程序创建 Borland OMF 导入库: IMPLIB -a "whatever.omf" "whatever.dll",其中 DLL 文件是由 MSVC 创建的。
-a 选项是为了与 Microsoft 兼容。生成的 OMF(Borland 的导入库文件格式)与指定导出函数及其调用约定的头文件相结合应该可以工作...(我相信 IMPLIB 存在于 C++ Builder 5 中。)
http://docs.embarcadero.com/products/rad_studio/ radstudio2007/RS2007_helpupdates/HUpdate4/EN/html/devwin32/implib_xml.html
You can create Borland OMF import libaries with Borland's IMPLIB utility: IMPLIB -a "whatever.omf" "whatever.dll", where the DLL file is that created by MSVC.
The -a option is for Microsoft compatibility. The generated OMF (Borland's import library file format), combined with a header file that specifies the exported functions and their calling convention(s) should work... (I believe IMPLIB was around in C++ Builder 5.)
http://docs.embarcadero.com/products/rad_studio/radstudio2007/RS2007_helpupdates/HUpdate4/EN/html/devwin32/implib_xml.html