Using a Borland C++ Builder DLL in Visual C++ 2005

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by QnVkZHkgTG » Wed, 21 Mar 2007 03:29:19


I have been searching and trying and can't seem to get the a DLL created with
Borland C++ Builder to 'resolve' simbols when used with Visual C++ 2005.

CBCompile, CBDeCompile, & CBRenumber always seem to be undefined in one form
or another.

I have tried creating an import library using lib.exe ..
I have tried several variations of the .def file.

Does anyone know the magic?

**** The header file looks like:
extern "C" bool __stdcall
CBCompile( char*, int*, int, int, int, char*, char*, char*, char* );
extern "C" bool __stdcall
CBDeCompile( char*, int*, int, int, char*, int, char*, char*, char*,
char* );
extern "C" bool __stdcall
CBRenumber( char*, int*, int, int, int, char*, char*, char*, char* );


**** My ControlBasic.def looks like this:

LIBRARY ControlBasic.dll

EXPORTS
_@@Descriptors@Finalize = @@Descriptors@Finalize ;
__linkproc__ Descriptors::Finalize
_@@Descriptors@Initialize = @@Descriptors@Initialize ;
__linkproc__ Descriptors::Initialize
_@@Unit2@Finalize = @@Unit2@Finalize ;
__linkproc__ Unit2::Finalize
_@@Unit2@Initialize = @@Unit2@Initialize ;
__linkproc__ Unit2::Initialize
_CBCompiler = CBCompile ;
CBCompile
_CBDeCompile = CBDeCompile ;
CBDeCompile
_CBRenumber = CBRenumber ;
CBRenumber
; _Form2 @9 ; _Form2
; ___CPPdebugHook @8 ; ___CPPdebugHook

*** The output from dumpbin is:

Microsoft (R) COFF/PE Dumper Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.



Dump of file ControlBasic.dll

File Type: DLL

Section contains the following exports for ControlBASIC.dll

00000000 characteristics
0 time date stamp Wed Dec 31 19:00:00 1969
0.00 version
1 ordinal base
9 number of functions
9 number of names

ordinal hint RVA name

7 0 00018F24 @@Descriptors@Finalize
6 1 00018F14 @@Descriptors@Initialize
5 2 00015C40 @@Unit2@Finalize
4 3 00015C30 @@Unit2@Initialize
2 4 000156B4 CBCompile
1 5 00014F4C CBDeCompile
3 6 00015BC0 CBRenumber
9 7 00036B74 _Form2
8 8 0003122C ___CPPdebugHook

Summary

16000 .data
1000 .edata
1000 .idata
4000 .reloc
1000 .rsrc
30000 .text
1000 .tls

--
Buddy Lott
 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by Brian Mut » Wed, 21 Mar 2007 05:19:41

It's a hopeless cause to try to link DLL's that have been created by
different compilers. You might get lucky with only the simplest of compiles
(where extern "C" is used, and no parameters passed, for example).

Do it the right way: recompile all the source code using one C++ compiler
only.

Brian

 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by Brian Mut » Wed, 21 Mar 2007 05:39:19

I should add that COM was invented for the very purpose of allowing one
binary executable call another binary DLL, even though they were compiled
using different compilers, perhaps even different compiler languages. You
might want to consider creating a COM DLL wrapper around your DLL for this
purpose.

Brian
 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by Ben Voig » Wed, 21 Mar 2007 05:43:41


Nonsense. This is the whole purpose of a DLL/shared library. Otherwise
everyone would have to compile with the same tools used to build windows.


No, but use the library manager tool that comes with your compiler (for
VC++, it's LIB.EXE) to create an import library in the format your compiler
uses. The export table of a DLL is totally standardized, but the static
import libraries aren't.
 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by Ben Voig » Wed, 21 Mar 2007 05:45:41


Are you sure it's stdcall? stdcall usually ends up with an @NN appended to
the name indicating the total size of the parameters passed on the stack.
 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by Brian Mut » Wed, 21 Mar 2007 07:57:46


Let me put it this way.... One of the issues with C++ compilers is name
mangling, which is not standardized across C++ compiler vendors.
VB6 does it own funny thing as well. So you can't just mix the dll's out of
the box. You have to ensure the entry points are understood by both parties,
and you need to ensure that the passed parameters are the same size and in
the same order.

Brian
 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by QnVkZHkgTG » Wed, 21 Mar 2007 11:59:00

am a little closer...

Changing my ControlBasic.def to

LIBRARY CONTROLBASIC.DLL

EXPORTS
_@@Descriptors@Finalize = @@Descriptors@Finalize ;
__linkproc__ Descriptors::Finalize
_@@Descriptors@Initialize = @@Descriptors@Initialize ;
__linkproc__ Descriptors::Initialize
_@@Unit2@Finalize = @@Unit2@Finalize ;
__linkproc__ Unit2::Finalize
_@@Unit2@Initialize = @@Unit2@Initialize ;
__linkproc__ Unit2::Initialize
CBCompile@36 = _CBCompile ;
CBCompile
CBDeCompile = _CBDeCompile ;
CBDeCompile
CBRenumber = _CBRenumber ;
CBRenumber
; _Form2 @9 ; _Form2
; ___CPPdebugHook @8 ; ___CPPdebugHook

and my header to

extern "C" bool __cdecl
CBCompile( char*, int*, int, int, int, char*, char*, char*, char* );
extern "C" bool __cdecl
CBDeCompile( char*, int*, int, int, char*, int, char*, char*, char*,
char* );
extern "C" bool __cdecl
CBRenumber( char*, int*, int, int, int, char*, char*, char*, char* );

caused all my unresolves to go away.

However it left me with a second problem....

I am getting this runtime error:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a
function call. This is usually a result of calling a function declared with
one calling convention with a function pointer declared with a different
calling convention.

I am still trying to diagnose this.


--
Buddy Lott


"Ben Voigt" wrote:

 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by changli » Wed, 21 Mar 2007 16:26:56

Hi, Buddy,
The error indicates that the stack pointer (ESP) was not properly saved due
to a mismatch in function-calling convention. You may try using __stdcall
instead of __cdecl in your situaltion.

Also, you may refer to:
Global Conventions
http://www.yqcomputer.com/
tml/askgui08072001.asp

Hope this helps. Please feel free to let us know if you have any other
questions or concerns.

Best regards,
Charles Wang
Microsoft Online Community Support
=====================================================
Get notification to my posts through email? Please refer to:
http://www.yqcomputer.com/ #notif
ications

If you are using Outlook Express, please make sure you clear the check box
"Tools/Options/Read: Get 300 headers at a time" to see your reply promptly.


Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://www.yqcomputer.com/
======================================================
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================
 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by QnVkZHkgTG » Wed, 21 Mar 2007 21:22:05

i Charles,

If i do nothing besides changing the calling converntion to __stdcall, then
I get these unresolves during link:

Error 17 error LNK2019: unresolved external symbol _CBCompile@36 referenced
in function "int __stdcall compileFile(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > &,class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > &,class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > &,class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > &,int &,int &,int &,char &,char &)"
(?compileFile@@YGHAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@000AAH11AAD2@Z) KMDCompile.obj
Error 18 error LNK2019: unresolved external symbol _CBDeCompile@40
referenced in function "int __stdcall decompileFile(class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > &,class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > &,class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > &,class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > &,int &,int &,int &,char
&,char &,unsigned char)"
(?decompileFile@@YGHAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@000AAH11AAD2E@Z) KMDCompile.obj
Error 19 fatal error LNK1120: 2 unresolved
externals U:\Projects\OldKMDCompile2\Debug\KMDCompile.exe 1

I have not been able to figure out the correct DEF syntax to get rid of
them. Any ideas?

--
Buddy Lott


"Charles Wang[MSFT]" wrote:

 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by QnVkZHkgTG » Wed, 21 Mar 2007 21:35:46

finally got past the linker & Runtime #0 problem, by changing the
ControlBasic.def to LIBRARY ControlBasic.dll

EXPORTS
_@@Descriptors@Finalize = @@Descriptors@Finalize ;
__linkproc__ Descriptors::Finalize
_@@Descriptors@Initialize = @@Descriptors@Initialize ;
__linkproc__ Descriptors::Initialize
_@@Unit2@Finalize = @@Unit2@Finalize ;
__linkproc__ Unit2::Finalize
_@@Unit2@Initialize = @@Unit2@Initialize ;
__linkproc__ Unit2::Initialize
CBCompile@36 = CBCompile ;
CBCompile
CBDeCompile@40 = CBDeCompile ;
CBDeCompile
_CBRenumber = CBRenumber ;
CBRenumber
; _Form2 @9 ; _Form2
; ___CPPdebugHook @8 ; ___CPPdebugHook

But know I am getting some kind of kernel crash in __delayLoadHelper2.

Here is crash message:

Unhandled exception at 0x7c812a5b in KMDCompile.exe: 0xC06D007F: Procedure
not found.

--
Buddy Lott


"Buddy Lott" wrote:

 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by Ben Voig » Wed, 21 Mar 2007 21:53:31

> CBCompile@36 = CBCompile ;
[snip]


Perhaps the actual name in the DLL is decorated with an underscore or @NN?
Or you are missing one of the dependencies of that DLL. Use Dependency
Walker to check this easily, it will also tell you exactly which procedure
wasn't found.
 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by QnVkZHkgTG » Wed, 21 Mar 2007 22:25:18

Dependency Walker is saying that CBCOmpiler@36 is 'not bound' which I assumes
means it was not found. But I do not see anything obvious about why it is not
bound.

Whether I look at decorated or undecorated names, it looks like everything
is correct.

Any ideas?

--
Buddy Lott
 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by QnVkZHkgTG » Wed, 21 Mar 2007 22:38:33

I get the feeling that sometimes I am running around in circles ....

When I use the Profile option in Dependency walker, it seems to be telling
me that the wrong function name is being looked up. For instance, I am
calling CBDeCompile but at runtime, CBDeCompiler@40 is being looked for.

This would seem to indicate that Exports are flip (i.e. CBDeCompile@40
should be on the right instead of the left. When I do that, I can and
unresolved on CBDecompile@40.

Does anyone know the magic?



--
Buddy Lott
 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by Ben Voig » Wed, 21 Mar 2007 22:59:50


Look at the DLL's export table as well as your program's import table.
 
 
 

Using a Borland C++ Builder DLL in Visual C++ 2005

Post by Ben Voig » Wed, 21 Mar 2007 23:01:11


That's three different flavors of spelling and capitalization.... I'd verify
the exact spelling.