C++ Builder Lib mit Visual C++
-
ich habe eine DLL datei geschrieben und diese mit dem C++ Builder compiliert. die Lib datei die nur die exportierten symbole enthält läuft nun unter Visual C++ nicht. was kann ich tun das es doch funktioniert?
-
Son Zufall, habe ich gestern Zufällig gegoogelt und gespeichert.
Linking a Borland DLL with Microsoft Visual C++ v43173 Linking a Borland DLL
with Microsoft Visual C++ v4
Last update 02/03/97NUMBER : 3173
PRODUCT : Borland C++
VERSION : 5.0
OS : All
DATE : January 3, 1997Linking a Borland DLL with Microsoft Visual C++ v4.0
Preface
This document is intended to assist developers in working with
both Borland C++ and
Microsoft Visual C++. Specifically, it covers using DLLs built
with Borland C++ with
Microsoft Visual C++ version 4.0.Important Notes
1. The Microsoft Visual C++ (MSVC) Compiler is case sensitive
and this cannot be
changed by a switch or IDE option. Borland C++ 5.0 (BC5) as well
as previous versions
of Borland C++ provide an option inside the Integrated
Development Environment (IDE)
to toggle case sensitivity in the linking phase. The "case
sensitive link" option in BC5's
IDE must be turned on to force creation of a DLL or .LIB file
that may be linked to by
the MSVC linker. This option is located under the
Options|Project|Linker|General menu
selection.2. MSVC always generates underscores as the first byte of a
function name. This cannot
be changed by a switch or IDE option. Borland C++ 5.0 provides
an option for this. The
"generate underscores" option must be turned on in the BC5 IDE
when compiling/linking
the DLL code. The option is located under the
Options|Project|Compiler Output menu
inside the IDE.3. Inside the Borland C++ IDE, specify "C Calling Convention"
IDE for this DLL. This
option is located under the Options|Project|16-bit
Compiler|Calling Convention or the
Options|Project|32-bit Compiler|Calling Convention menu item
accordingly. In the
MSVC IDE, specify "cdecl" calling convention.If No Source is Available for the DLL:
If you do not have the source to the Borland DLL, you may not
know the calling
convention used when it was built. "C Calling Convention" is
probably the most
common calling convention. Borland provides a utility to create
a .LIB file from a DLL.
This program is called "IMPLIB." Use this command with the "-c"
switch to generate a
.LIB file with case-sensitive symbols. You can then browse the
.LIB file and look for
your function names. They will appear in the .LIB file with
names similar to the
following example:__imp__FunctionName
This means that when the DLL was built "declspec(dllexport)" was
used when defining
the functions and their prototypes. Build a .DEF file from this
.LIB file as in the
examples below. Next, build a new .LIB using the Microsoft LIB
utility, and use this
with the MSVC compiler.If the function names in the .LIB do not look like the example
above, some other calling
convention was used. It will take a considerable amount of work
to discover how it was
built. Refer to Microsoft Knowledgebase article # Q131313 for
some help with this
process.If the DLL Source is Available:
Be sure that the options described in items 1, 2 and 3 above are
set correctly in both
development environments. Next, change all of the exportable
functions in the DLL by
putting "declspec(dllexport)" in front of the function
definition.In the header file for the DLL, include some code as in the
example below:#ifndef _SAMPLE_H
#define _SAMPLE_H#ifdef EXPNETFUNCS
#define EXPNETTYPE __declspec( dllexport )
#else
#define EXPNETTYPE __declspec( dllimport )
#endif EXPNETFUNCS#ifdef __cplusplus
extern "C" {
#endif
EXPNETTYPE SHORT WINAPI BeginNetworkOps(int);
EXPNETTYPE SHORT WINAPI EndNetworkOps(SHORT);
#ifdef __cplusplus
}
#endif
#endifIn the DLL source code, where the header file is included,
#define EXPNETFUNCS and
the correct prototype will be generated. In the application
program that includes this
header file, DO NOT define EXPNETFUNCS and the correct code will
be generated
there. Don't forget to put 'extern "C" {' around these functions
in the header file for the
DLL, if this DLL is written in C++. This prevents C++'s name
decorations for these
functions and keeps the name the same so external programs can
link with them.Now rebuild the DLL. Use Borland's IMPDEF command to generate a
.DEF file. Use
the following command to generate a .DEF file:IMPDEF c:\msproj\sample.def c:\bcproj\sample.dll
Do not use the "-h" switch for the IMPDEF command. MSVC does not
use any "hints"
when processing .DEF files. Next, use the Microsoft LIB command
to generate a .LIB
file from the .DEF file created above. The following command
will generate the LIB
file:LIB /def:c:\msproj\sample.def /out:c:\msproj\sample.lib
Include this lib file in the MSVC project. Then compile and link
it. It will fail in the link
step due to unresolved external references. Nevertheless, the
error messages provide
some very important information. The error messages in MSVC 4.0
will look like the
following:MSSAMPLE.OBJ : error LNK2001: unresolved external symbol
__imp__BeginNetworkOps@12
MSSAMPLE.OBJ : error LNK2001: unresolved external symbol
__imp__EndNetworkOps@8The "@" following the function name in the error message has a
number after it. This
number represents the number of bytes that the linker reserves in
the stack for arguments
passed to the function. MSVC 4.0 uses this number and the "@"
sign as part of the
function names You cannot prevent that from happening if you use
the cdecl calling
convention. This is why you get the unresolved reference; it
actually does not exist in
the .LIB file.To fix this problem edit the .DEF file created in a previous
step, and add the "@" sign
and the number to the end of the exported function names. Try to
recompile the MSVC
application again. It should link properly. The linker strips
off the "@n" on the function
names when it produces the executable file, and it will find the
function in the DLL at
run time.Knowledge Base Documents
The Microsoft Knowledge Base document Q131313 referred to earlier
is titled "How to
Create 32-bit Import Libraries Without .OBJs or Source."
Knowledge Base documents
are available from the Microsoft Support Web page
http://www.microsoft.com/support/.DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
you received with the Borland product to which this information
pertains.
-
danke marmey das scheint was zu sein.
also ich möchte folgendes damit es wirklich klar ist:1. mit dem CBuilder code ich eine DLL dynamisch
2. mit dem Visual C++ 6.0 code ich ein anderes projekt, da möchte ich dann die DLL die ich mit CBuilder compiliert habe, nutzen. Dazu füge ich die 256 bytes grosse Lib vom CBuilder erstellt, dem VC projekt hinzu. diese Lib ist hald klein da sie echt nur die exportierten symbole enthält und nicht etwa die ganze DLL als lib. gut, dieser abschnitt dürfte interessat sein:1. The Microsoft Visual C++ (MSVC) Compiler is case sensitive
and this cannot be
changed by a switch or IDE option. Borland C++ 5.0 (BC5) as well
as previous versions
of Borland C++ provide an option inside the Integrated
Development Environment (IDE)
to toggle case sensitivity in the linking phase. The "case
sensitive link" option in BC5's
IDE must be turned on to force creation of a DLL or .LIB file
that may be linked to by
the MSVC linker. This option is located under the
Options|Project|Linker|General menu
selection.2. MSVC always generates underscores as the first byte of a
function name. This cannot
be changed by a switch or IDE option. Borland C++ 5.0 provides
an option for this. The
"generate underscores" option must be turned on in the BC5 IDE
when compiling/linking
the DLL code. The option is located under the
Options|Project|Compiler Output menu
inside the IDE.3. Inside the Borland C++ IDE, specify "C Calling Convention"
IDE for this DLL. This
option is located under the Options|Project|16-bit
Compiler|Calling Convention or the
Options|Project|32-bit Compiler|Calling Convention menu item
accordingly. In the
MSVC IDE, specify "cdecl" calling convention.allerdings finde ich keiner dieser optionen im CBuilder optionenmenu. was nun?
-
obwohl doch. nur punkt 1 nicht.
1. = ???
2. müsste sein: "Unterstriche erzeugen / JA"
3. müsste sein: "Aufrufkonvention / C"
-
habe die lib datei nun mit implib erstellt. jetzt ist sie 1kB gross, geht mit dem VC aber immer noch nicht

ständig: engine.lib : fatal error LNK1136: invalid or corrupt file
-
Mehr helfen, wie den gefunden Artikel posten (Marmey bin ich unangemeldet), kann ich dir eigentlich auch nicht. Aber hast du dir auch wirklich alles durchgelesen?
If No Source is Available for the DLL:
If you do not have the source to the Borland DLL, you may not
know the calling
convention used when it was built. "C Calling Convention" is
probably the most
common calling convention. Borland provides a utility to create
a .LIB file from a DLL.
This program is called "IMPLIB." Use this command with the "-c"
switch to generate a
.LIB file with case-sensitive symbols. You can then browse the
.LIB file and look for
your function names. They will appear in the .LIB file with
names similar to the
following example:__imp__FunctionName
This means that when the DLL was built "declspec(dllexport)" was
used when defining
the functions and their prototypes. Build a .DEF file from this
.LIB file as in the
examples below. Next, build a new .LIB using the Microsoft LIB
utility, and use this
with the MSVC compiler.If the function names in the .LIB do not look like the example
above, some other calling
convention was used. It will take a considerable amount of work
to discover how it was
built. Refer to Microsoft Knowledgebase article # Q131313 for
some help with this
process.Das scheint ja in dem Zusammenhang das du die Lib mit Implib erstellst wichtig zu sein und deine Aussage klingt nicht so als hättest du das gemacht.
-
habs nun doch geschafft. ich musste zuerst seitens borland mit impdef eine def der dll erstellen. anhand dieser def dann seitens microsoft mit LIB die eigentliche lib erstellen.
ABER jetzt krieg ich nen linker error das die symbole nicht aufgelöst sind??? so ne scheisse ich kack noch ab

error LNK2001: unresolved external symbol __imp__Start_Vote
.\Profilemp/mode.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe
-
Meine DLL extern "C" __declspec(dllexport) void Start_Vote(int); Funktion: void Start_Vote(int Num){//.....} Die andere DLL extern "C" __declspec(dllimport) void Start_Vote(int); Aufruf: Start_Vote(677);