Re: Problems linking a BCB-DLL (.lib) under MSVC
From: Tamas Demjen (tdemjen_at_yahoo.com)
Date: 02/02/05
- Next message: Willy Denoyette [MVP]: "Re: .Net Remoting with a VB6 App"
- Previous message: Larry Brasfield: "Re: Sometjing to solve my problem"
- In reply to: Uli: "Problems linking a BCB-DLL (.lib) under MSVC"
- Next in thread: Uli: "Re: Problems linking a BCB-DLL (.lib) under MSVC"
- Reply: Uli: "Re: Problems linking a BCB-DLL (.lib) under MSVC"
- Reply: Carl Daniel [VC++ MVP]: "Re: Problems linking a BCB-DLL (.lib) under MSVC"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Willy Denoyette [MVP]: "Re: .Net Remoting with a VB6 App"
- Previous message: Larry Brasfield: "Re: Sometjing to solve my problem"
- In reply to: Uli: "Problems linking a BCB-DLL (.lib) under MSVC"
- Next in thread: Uli: "Re: Problems linking a BCB-DLL (.lib) under MSVC"
- Reply: Uli: "Re: Problems linking a BCB-DLL (.lib) under MSVC"
- Reply: Carl Daniel [VC++ MVP]: "Re: Problems linking a BCB-DLL (.lib) under MSVC"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|