开发者

Using a Visual C++ DLL in old Borland C?

I've got to support an old app written in C using the old Borland Compiler (BC 5).

Unfortun开发者_StackOverflowately 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


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();


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜