Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calling Functions in a Delphi DLL from Visual C++ application

572 views
Skip to first unread message

B Banerjee

unread,
Sep 17, 1998, 3:00:00 AM9/17/98
to
Hi Anybody Help me!

I have developed a DLL using Delphi. But to call the functions in that
DLL from a Visual C++ application, using IMPLICIT linking (i.e., making
an import library and linking with it) makes problems. I have created an
import library with Microsoft LIB /DEF<MYDEFFILENAME.DEF>
But the Visual C++ compiler mangles the name of function..
e.g. My function Name is

function DisplayStatus:Integer; stdcall; in delphi DLL.

I have given its prototype in VCPP application as

extern "C" int APIENTRY DisplayStatus();

But the VCPP compiler mangles the name as _DisplayStatus@0, which is not
there in the DLL. So the linker gives error. If I try with
GetProcAddress it is OKAY. But I have to do it with IMPORT LIB . Pleae
help me back at joj...@hotmail.com

Steve Schafer (TeamB)

unread,
Sep 17, 1998, 3:00:00 AM9/17/98
to
On Thu, 17 Sep 1998 13:40:28 +0530, B Banerjee <bir...@hotmail.com>
wrote:

>I have developed a DLL using Delphi. But to call the functions in that
>DLL from a Visual C++ application, using IMPLICIT linking (i.e., making
>an import library and linking with it) makes problems. I have created an
>import library with Microsoft LIB /DEF<MYDEFFILENAME.DEF>
>But the Visual C++ compiler mangles the name of function..

There has to be a way to make VC++ emit non-decorated function names;
otherwise, a VC++ application couldn't call any of the Windows API
functions. Unfortunately, I don't use VC++ and don't know what you
have to do.

As a short-term fix, you can export the Delphi functions with
decorated names:

exports
Foo name 'Foo@0',
Bar name 'Bar@12';

-Steve


Wayne Niddery (TeamB)

unread,
Sep 17, 1998, 3:00:00 AM9/17/98
to
B Banerjee wrote in message <3600C3F4...@hotmail.com>...
>Hi Anybody Help me!

>
>I have developed a DLL using Delphi. But to call the functions in that
>DLL from a Visual C++ application, using IMPLICIT linking (i.e., making
>an import library and linking with it) makes problems. I have created an
>import library with Microsoft LIB /DEF<MYDEFFILENAME.DEF>
>But the Visual C++ compiler mangles the name of function..
>e.g. My function Name is
>
>function DisplayStatus:Integer; stdcall; in delphi DLL.
>
>I have given its prototype in VCPP application as
>
>extern "C" int APIENTRY DisplayStatus();


Just a guess, but add stdcall to the above VC++ prototype. That should tell
VC++ to not mangle the names.

--
Wayne Niddery - WinWright Consulting
Delphi, C++Builder, JBuilder, InterDev -- Amazon.com Associate
at http://home.ican.net/~wniddery/RADBooks.html
...remove chaff when replying...

Steve Schafer (TeamB)

unread,
Sep 17, 1998, 3:00:00 AM9/17/98
to
On Thu, 17 Sep 1998 13:15:00 -0400, "Wayne Niddery (TeamB)"
<winw...@chaffshaw.wave.ca> wrote:

>Just a guess, but add stdcall to the above VC++ prototype. That should tell
>VC++ to not mangle the names.

That, unfortunately, is not enough. I recently had an extensive
back-and-forth with a developer over the exported function names in a
DLL that he had written, and we never did figure out how to get VC++
to refrain from appending the @XXX, even though all of the functions
were indeed stdcall.

-Steve


Krasimir Stoyanov

unread,
Sep 18, 1998, 3:00:00 AM9/18/98
to
Why don't you try DLLImport instead of APIENTRY if I remember the key word correctly?

B Banerjee wrote:

> Hi Anybody Help me!
>
> I have developed a DLL using Delphi. But to call the functions in that
> DLL from a Visual C++ application, using IMPLICIT linking (i.e., making
> an import library and linking with it) makes problems. I have created an
> import library with Microsoft LIB /DEF<MYDEFFILENAME.DEF>
> But the Visual C++ compiler mangles the name of function..
> e.g. My function Name is
>
> function DisplayStatus:Integer; stdcall; in delphi DLL.
>
> I have given its prototype in VCPP application as
>
> extern "C" int APIENTRY DisplayStatus();
>

Armin Schweitzer

unread,
Sep 18, 1998, 3:00:00 AM9/18/98
to
I don't know much about it but I read somewhere that
you have to create special procedure prototypes in your
delphi-program if you want these to be called from a C++
program! Have a look at "stdcall" in the help.

Armin

Krasimir Stoyanov schrieb in Nachricht <360180B8...@internet-bg.bg>...

Sebastian Bargmann

unread,
Sep 18, 1998, 3:00:00 AM9/18/98
to
>I have developed a DLL using Delphi. But to call the functions in that
>DLL from a Visual C++ application, using IMPLICIT linking (i.e., making
>an import library and linking with it) makes problems. I have created an
>import library with Microsoft LIB /DEF<MYDEFFILENAME.DEF>
>But the Visual C++ compiler mangles the name of function..
>e.g. My function Name is
>
>function DisplayStatus:Integer; stdcall; in delphi DLL.
>
>I have given its prototype in VCPP application as
>
>extern "C" int APIENTRY DisplayStatus();
>
>But the VCPP compiler mangles the name as _DisplayStatus@0, which is not
>there in the DLL. So the linker gives error. If I try with
>GetProcAddress it is OKAY. But I have to do it with IMPORT LIB

You actually have to create the DLL in VC (well, almost)!

Implement all your exported prototypes in VC with empty bodies. Then put the
function names in a DEF file below the EXPORTS keyword. When you build the
project VC will create a new DLL for you (just ignore it) and more
important, an import library that "maps" the mangled names to the correct
exported names in the Delphi DLL.

This is also explained in a MS knowledge base article.

--
Sebastian Bargmann
Remove NOSPAM etc...

Marco Carrasco

unread,
Oct 14, 1998, 3:00:00 AM10/14/98
to
The original question involved STDCALL exports, but the following will work
using CDECL. I've used it several times, and will try it with STDCALL when I
get home tonight...

delphi calls:
function blah(x : integer): integer; cdecl; external 'blah.dll';

C++ function:
extern "C" _declspec(dllexport) int blah(int x){
return x;
}

the "C" tells it to maintain standard names, the _declspec tells it which
convention and tells it to export... I think you could use _stdcall(dllexport)
too, but don't have delphi here to test it.

Hope this helps...
--Jacob Thurman

0 new messages