Board index » cppbuilder » Linking a MicroSoft dll into Borland project

Linking a MicroSoft dll into Borland project


2005-07-20 05:08:24 AM
cppbuilder64
Is it possible to create a dll using MicroSoft Visual C++ .net and then load that dll into a Borland project ? Several attempts following published examples have all failed. And to think I thought different platforms might be an issue.
thanks, Doug.
 
 

Re:Linking a MicroSoft dll into Borland project

Doug DeVoe wrote:
Quote
Is it possible to create a dll using MicroSoft Visual C++ .net and then load that dll into a Borland project ? Several attempts following published examples have all failed. And to think I thought different platforms might be an issue.

thanks, Doug.
Only if it is unmanaged - pure c/c++ win32 dll. .NET dll can not be used
from other non .NET enviroments, as far as I know.
As for how to do it just go to this url
groups-beta.google.com
and enter this as a search string or something along these lines
using vc dll in C++ builder
Darko
 

Re:Linking a MicroSoft dll into Borland project

Export individual functions and not classes.
Run impdef on the DLL to create a module definition file, a *.DEF file.
Look in it to see the decorated versions of the function names uses by the
DLL and add aliases to provide names such as your program would use.
If the exported items are extern "C" __stdcall (aka extern "C" WINAPI)
then the names will be the same as those in the source code and should not
require an alias.
If they are only extern "C" then, depending upon which version of Visual C++
and on the options settings in Visual C++, they may need the addition of a
leading underscore.
By the Microsoft and Borland standards, FuncName in a C program corresponds
to a public name of _FuncName but later versions of Visual C++ no longer use
the leading underscore (but other Microsoft language products do).
If the exported items are C++ functions not decorated with extern "C" then
the names will be mangled, items added to indicate they are C++ and to
indicate the number and types of calling arguments. While that is a
standard technique, when Microsoft decided to create a C++ compiler they
made a deliberate decision to use a name mangling technique which was not
compatible with the existing Borland compiler. You will have to use an
alias in the module definition file.
An alias is simple. All you do is add something like this:
_AliasedFunctionName = dllname.WhateverNameIsInTheDll
To see aliases in the compier help, start the help, click the Index tab,
type in Module Definition Files, Click Ok and select the EXPORTS Statement
link.
Later, when building your program, you do one of two things:
- Add the module definition file to the project instead of using
an import library
Note that if building from the command line, module definition
files are listed on the ilink32 command line following the libraries,
separated from them by a comma.
- Use implib.exe to create an import library from the module
definition file and add that import library to the project
. Ed
Quote
Doug DeVoe wrote in message
news:42dd6bc8$ XXXX@XXXXX.COM ...

Is it possible to create a dll using MicroSoft Visual C++ .net
and then load that dll into a Borland project ? Several
attempts following published examples have all failed. And
to think I thought different platforms might be an issue.
 

{smallsort}

Re:Linking a MicroSoft dll into Borland project

thanks, Ed... appreciate your time. I had to discover some refinements to your procedure but it eventually worked. See below:
VC++ .net file header:
extern "C"
{
__declspec( dllexport ) int AddTwoNumbers(int n1, int n2);
}
Then use IMPDEF and IMPLIB as previously described without adding name alias.
Add the *.lib file to Borland project.
In the Borland file header the declaration is:
extern "C" __stdcall int AddTwoNumbers(int n1, int n2);
I would have thought that Inprise would publish more info on this process since it encourages people to stick with their product, and/or convert from MS to Borland.
Doug.
 

Re:Linking a MicroSoft dll into Borland project

one more item I discovered... the *.dll file created by MS VC++ .net must also be in the Borland project directory.
I don't understand why both the *.lib and *.dll files
are needed but it seems to work.
"Doug" < XXXX@XXXXX.COM >wrote:
Quote

thanks, Ed... appreciate your time. I had to discover some refinements to your procedure but it eventually worked. See below:

VC++ .net file header:

extern "C"
{
__declspec( dllexport ) int AddTwoNumbers(int n1, int n2);
}

Then use IMPDEF and IMPLIB as previously described without adding name alias.

Add the *.lib file to Borland project.

In the Borland file header the declaration is:

extern "C" __stdcall int AddTwoNumbers(int n1, int n2);

I would have thought that Inprise would publish more info on this process since it encourages people to stick with their product, and/or convert from MS to Borland.

Doug.