Re: Problems linking a BCB-DLL (.lib) under MSVC

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Tamas Demjen (tdemjen_at_yahoo.com)
Date: 02/02/05


Date: Wed, 02 Feb 2005 10:41:23 -0800

I think __fastcall is Borland specific, it uses registers to pass
function arguments, and it's not compatible with Microsoft. The two
others must work (__stdcall and __cdecl). I think in the DEF file you
just have to list the names, without underscores:

EXPORTS
    SayHello1
    SayHello3
    SayHello4

the extern "C" keyword ensures that all mangling of function names is
turned off, so you just use the real name of the funciton, in plain
ASCII. No @, no _.

I usually use LoadLibrary and GetProcAddress, and this always works very
nicely between compilers (BCB and VC++), in both directions (VC++ DLL
and BCB app; BCB DLL and VC++ app).

Tom

Uli wrote:
> Hello,
>
> I'm trying to use a DLL (by static linking) which was compiled with Borland
> C++Builder (BCB) in Visual C++ (Visual-Studio 2003).
>
> All functions are declared with the directive 'extern "C"' so that a
> cross-compiler-usage must be possible.
>
> I created an import library (.lib) for MSVC by using the LIB function and
> using a .DEF file (as described in KB131313 -
> http://support.microsoft.com/default.aspx?scid=kb;en-us;131313)
>
> My DUMPBIN showed the following exports:
> ordinal hint RVA name
> 2 0 000012E4 @SayHello2
> 1 1 000012D0 SayHello1
> 3 2 000012F8 _SayHello3
> 4 3 0000130C _SayHello4
> 5 4 000090F8 ___CPPdebugHook
>
> So I created a .DEF as follows:
> EXPORTS
> @SayHello2
> SayHello1
> _SayHello3
> _SayHello4
>
> The .lib and .exp generation succeeded so far.
>
> The declaration (.h) used in BCB and included in MSVC later on is as follows:
> #ifndef __BCB2VC_DLL_H
> #define __BCB2VC_DLL_H
>
> #ifdef __BUILD_DLL__
> #define __DECL_SPEC__ __declspec(dllexport)
> #else
> #define __DECL_SPEC__ __declspec(dllimport)
> #endif //#ifdef __BUILD_DLL__
>
> extern "C" __DECL_SPEC__ void __stdcall SayHello1(void);
> extern "C" __DECL_SPEC__ void __fastcall SayHello2();
> extern "C" __DECL_SPEC__ void __cdecl SayHello3();
> extern "C" __DECL_SPEC__ void SayHello4();
>
> #endif //#ifndef __BCB2VC_DLL_H
>
> In my MSVC application I simply try to call the functions:
> int _tmain(int argc, _TCHAR* argv[])
> {
> SayHello1();
> SayHello2();
> SayHello3();
> SayHello4();
> }
>
> This lead to the result, that I received the following linker errors:
> Test.obj : error LNK2019: Nicht aufgelöstes externes Symbol
> '__imp__SayHello4', verwiesen in Funktion '_main'
> Test.obj : error LNK2019: Nicht aufgelöstes externes Symbol
> '__imp__SayHello3', verwiesen in Funktion '_main'
> Test.obj : error LNK2019: Nicht aufgelöstes externes Symbol
> '__imp_@SayHello2@0', verwiesen in Funktion '_main'
> Test.obj : error LNK2019: Nicht aufgelöstes externes Symbol
> '__imp__SayHello1@0', verwiesen in Funktion '_main'
> Debug/USE_BCB_DLL.exe : fatal error LNK1120: 4 unaufgelöste externe Verweise
>
> ---
>
> when I create the .LIB with the .DEF like:
> EXPORTS
> SayHello2
> SayHello1
> SayHello3
> SayHello4
>
> and call the functions with (calling SayHello1 and SayHello2 doesn't succeed
> at all):
> int _tmain(int argc, _TCHAR* argv[])
> {
> //SayHello1();
> //SayHello2();
> SayHello3();
> SayHello4();
> }
>
> then my application starts (which means linking succeeds). But while
> starting, a MessageBox appears, which says:
> 'The entrypoint of "SayHello3" in "Test.dll" could not be found.'
>
> So what is wrong here? How do I manage to get to get my DLL run without
> changing the calling conventions (__stdcall / __fastcall) ?
>
> Thanks,
> Uli



Relevant Pages

  • Re: Export C++ class from a Borland DLL and use it in Microsoft VC
    ... Borland uses a different C runtime (including a different memory ... Use a C-style DLL. ... use pure extern "C" exports, but the functions themselves can accept and ... You must either not use enums in your interface, ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Export C++ class from a Borland DLL and use it in Microsoft VC
    ... Borland uses a different C runtime than Visual Studio. ... Of course, it is not impossible to use a DLL across compilers, even across different languages. ... You still need to use pure extern "C" exports, but the functions themselves can accept and return C++ classes. ... You must either not use enums in your interface, or modify Borland's compiler settings for your particular cpp file. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Convert C-Builder program to Delphi?
    ... > quite separate from the function declaration itself. ... >this DLL ... >way the only place anything needs to be changed is in the #define macro. ... Exports SomeDLL_Open Name 'SomeDLL_Open'; ...
    (comp.lang.pascal.delphi.misc)
  • Re: Convert C-Builder program to Delphi?
    ... > quite separate from the function declaration itself. ... >this DLL ... >way the only place anything needs to be changed is in the #define macro. ... Exports SomeDLL_Open Name 'SomeDLL_Open'; ...
    (comp.lang.cpp)
  • Re: silverfrost IDE
    ... to make a dll that gets picked up by VB. ... I do not believe that Salford Fortran uses .def files ... exports according to your preference. ... Salford provides its own linker which AFAIK does not use .def ...
    (comp.lang.fortran)