Borland vs. MSVC Calling Convention 
Author Message
 Borland vs. MSVC Calling Convention

Greets Paul,

    You were definitely one the right track.  I have been able to create
VC++ API DLLs that worked with Borland by doing the following:

1)  Use extern "C" to keep 'C' linkage on the names;
2)  Use __stdcall to use the old 'Pascal' calling convention;
and (important)
3)  Create a .DEF file with the names and ordinals of your exports.

example:

// header file declaration
extern "C" {
    void __stdcall MyExport(int iValue);

Quote:
}

// function definition
void __stdcall MyExport(int iValue)
{

Quote:
}

// .DEF file
LIBRARY "MYAPI"
EXPORTS

Regards,

Joe


Quote:
> I'm using a 3rd party app that was written in Delphi.  This app allows
> the use of extension DLLs -- you can direct the app to call functions
> in your own custom DLL, subject to the app's specification.  I created
> my DLL in VC6, but there is a problem when the 3rd party app tries to
> call a function in the DLL.  In VC6, the exported function name gets
> mangled in a way that the delphi can't recognize.

> I've tried using the extern "C" directive to prevent the mangling, but
> the __stdcall directive also mangles the function names.  Not only
> that, but the parameter ordering and stack cleanup must be compatible.

> Has anyone found a way to declare a MSCV exported function so that
> Delphi (or Borland C++) can see (and correctly call) it?

> Thanks
> Paul

> ----
> Paul Hurley
> Caliban Computing
> http://www.*-*-*.com/
> Spam resistant return email address.



Tue, 30 Jul 2002 03:00:00 GMT  
 Borland vs. MSVC Calling Convention

Quote:
> I'm using a 3rd party app that was written in Delphi.  This app allows
> the use of extension DLLs -- you can direct the app to call functions
> in your own custom DLL, subject to the app's specification.  I created
> my DLL in VC6, but there is a problem when the 3rd party app tries to
> call a function in the DLL.  In VC6, the exported function name gets
> mangled in a way that the Delphi can't recognize.

> I've tried using the extern "C" directive to prevent the mangling, but
> the __stdcall directive also mangles the function names.  Not only
> that, but the parameter ordering and stack cleanup must be compatible.

> Has anyone found a way to declare a MSCV exported function so that
> Delphi (or Borland C++) can see (and correctly call) it?

In addition to the other reply, I offer this method which does not involve
redeclaring the function.

An exported function in a DLL can be associated with multiple names.

The multiple aliases come in handy if you want to have a single DLL used by
multiple clients each with their own naming scheme, that is you want to
support both Delphi and VC/C++ clients using the native naming conventions.

All you need to do is use a construct like

EXPORTS


in the module definition file. The token on the right side of the equals
sign is the "real" name which you can get by using dumpbin/exports. On the
left side is the alias.

Regards,
Will



Tue, 30 Jul 2002 03:00:00 GMT  
 Borland vs. MSVC Calling Convention
Greets William,

    Yes, I've used aliases before, one case that comes to mind specifically
is when I had a Borland application load an add-in DLL written in Visual C++
and use GetProcAddress() to get a decorated export by name.  This is
definitely a useful feature, the only hidden 'gotcha' is that you need to
make sure that you are not masking name mangling that may be due to calling
conventions.

Regards,

Joe



Quote:


> > I'm using a 3rd party app that was written in Delphi.  This app allows
> > the use of extension DLLs -- you can direct the app to call functions
> > in your own custom DLL, subject to the app's specification.  I created
> > my DLL in VC6, but there is a problem when the 3rd party app tries to
> > call a function in the DLL.  In VC6, the exported function name gets
> > mangled in a way that the Delphi can't recognize.

> > I've tried using the extern "C" directive to prevent the mangling, but
> > the __stdcall directive also mangles the function names.  Not only
> > that, but the parameter ordering and stack cleanup must be compatible.

> > Has anyone found a way to declare a MSCV exported function so that
> > Delphi (or Borland C++) can see (and correctly call) it?

> In addition to the other reply, I offer this method which does not involve
> redeclaring the function.

> An exported function in a DLL can be associated with multiple names.

> The multiple aliases come in handy if you want to have a single DLL used
by
> multiple clients each with their own naming scheme, that is you want to
> support both Delphi and VC/C++ clients using the native naming
conventions.

> All you need to do is use a construct like

> EXPORTS


> in the module definition file. The token on the right side of the equals
> sign is the "real" name which you can get by using dumpbin/exports. On the
> left side is the alias.

> Regards,
> Will



Tue, 30 Jul 2002 03:00:00 GMT  
 Borland vs. MSVC Calling Convention

Quote:
>     Yes, I've used aliases before, one case that comes to mind
specifically
> is when I had a Borland application load an add-in DLL written in Visual
C++
> and use GetProcAddress() to get a decorated export by name.  This is
> definitely a useful feature, the only hidden 'gotcha' is that you need to
> make sure that you are not masking name mangling that may be due to
calling
> conventions.

Right but the aliases are additive. You are not masking so much as
enhancing. A function becomes known by many names and every environment can
refer to a target by a name that suits it.

Regards,
Will



Tue, 30 Jul 2002 03:00:00 GMT  
 Borland vs. MSVC Calling Convention
Greets William,

    To be honest I've never thought of using the 'alias' technique in the
.DEF file to create a single lib for multiple language/development
environments.  I did not know that multiple aliases to the same export could
be used, probably because I had not thought of that before!  It will,
however, be something of which to take note.

Regards,

Joe



Quote:


> >     Yes, I've used aliases before, one case that comes to mind
> specifically
> > is when I had a Borland application load an add-in DLL written in Visual
> C++
> > and use GetProcAddress() to get a decorated export by name.  This is
> > definitely a useful feature, the only hidden 'gotcha' is that you need
to
> > make sure that you are not masking name mangling that may be due to
> calling
> > conventions.

> Right but the aliases are additive. You are not masking so much as
> enhancing. A function becomes known by many names and every environment
can
> refer to a target by a name that suits it.

> Regards,
> Will



Wed, 31 Jul 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. msvc vs borland's builder

2. Calling convention: C vs PASCAL

3. How to call a device driver under borland C vs MS

4. Calling an exported function of a dll which are exported Stdcall calling convention

5. MFC Control OnCreate not called via VB, but called under MSVC

6. Borland vs MS vs Symantec ???

7. Borland vs MS vs Syma

8. C++ vs C conventions ?

9. Cdel vs Pascal convention

10. cdecl vs stdcall convention...

11. ANSI vs K&R Coding Conventions

12. Matching up Borland and MSVC Graphics Routines

 

 
Powered by phpBB® Forum Software