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

Calling a DLL from Delphi

82 views
Skip to first unread message

Andy Sandberg

unread,
Jun 8, 1998, 3:00:00 AM6/8/98
to

Hi!

I want to call a DLL from Delphi. But when I run my program Delphi gives an
error message saying "TEST.EXE is linked to MXREGEXP.DLL:RegComp that does
not exist."

What's wrong?

In Delphi RegComp( ) is declared like:

function RegComp(pPattern : PChar ) : longint ;
stdcall ; external 'mxregexp.dll' ;

The DLL is created with C++Builder 3.0. I have checked that function
RegComp() really is exported and the def-file look like this:

--- start

LIBRARY MXREGEXP.DLL

EXPORTS
@Classes@TList@$bctr$qqrv @1 ; Classes::TList::TList() __fastcall
@RegComp$qqspc @2 ; RegComp(char*) __stdcall

--- end

Please help, someone!

Thanks!

/Anders Sundberg


Ivan Detkov

unread,
Jun 8, 1998, 3:00:00 AM6/8/98
to

The name of the function is @RegComp$qqspc. It is better to use dynamic dll
loading (look at LoadLibrary function.) Other possibility is unmangle name
of the function. I believe that extern "C" function declaration in dll can
do it for you.

Ivan Detkov
Zedak Corp.

Andy Sandberg wrote in message <6lh642$57...@forums.borland.com>...

Brian Paisley

unread,
Jun 8, 1998, 3:00:00 AM6/8/98
to

Your problem is that RegComp is name mangled (caused by the __stdcall
directive).

If you change your definition to something like the following:

extern "C" long int __declspec(dllexport) RegComp(char*);

You should be able to load the function in Delphi at the expense of
adding an underscore to the pascal defininition (e.g., _Regcomp);

I'm a little new to C++Builder, so this isn't a perfect solution,
since I haven't figured out a way to get the dll to compile without
adding the underscore, but hopefully this helps you out.


On Mon, 8 Jun 1998 19:15:27 +0200, "Andy Sandberg" <sum...@tripnet.se>
wrote:

Andy Sandberg

unread,
Jun 9, 1998, 3:00:00 AM6/9/98
to

Thanks!

It worked!

/Andy

Brian Paisley wrote in message <357c2518...@forums.borland.com>...

Andy Sandberg

unread,
Jun 9, 1998, 3:00:00 AM6/9/98
to

Thanks!

It worked!

/Andy

Ivan Detkov wrote in message <6lh7n9$4n...@forums.borland.com>...


>The name of the function is @RegComp$qqspc. It is better to use dynamic dll
>loading (look at LoadLibrary function.) Other possibility is unmangle name
>of the function. I believe that extern "C" function declaration in dll can
>do it for you.
>
>Ivan Detkov
>Zedak Corp.
>
>Andy Sandberg wrote in message <6lh642$57...@forums.borland.com>...

Peter Below

unread,
Jun 9, 1998, 3:00:00 AM6/9/98
to

In article <357c2518...@forums.borland.com>, Brian Paisley wrote:
> Your problem is that RegComp is name mangled (caused by the __stdcall
> directive).
>
Slight correction, Brian. The __stdcall is innocent, the missing extern "C"
causes the mangling, which is the C++ default. If the __stdcall is left off
the function would need to be declared with cdecl calling convention on the
Delphi side.

Peter Below (TeamB) 10011...@compuserve.com)


Brian Paisley

unread,
Jun 9, 1998, 3:00:00 AM6/9/98
to

On Tue, 09 Jun 1998 21:17:37 +0200, Peter Below
<10011...@compuserve.com> wrote:

As I stated, I am new to C++Builder and was relying on the help
documentation, which states that, "__fastcall and _ _stdcall are
always name mangled in C++". Is this a documentation error?

Regards,
Brian

P.S. At the risk of being accused of cross-posting, do you happen to
know how to get the linker to drop those pesky underscores?

Peter Below

unread,
Jun 10, 1998, 3:00:00 AM6/10/98
to

> As I stated, I am new to C++Builder and was relying on the help
> documentation, which states that, "__fastcall and _ _stdcall are
> always name mangled in C++". Is this a documentation error?
>
Brian,

there are two kinds of mangling here, the one C++ does if you do not specify
extern "C", which encodes parameter number and type, and the one that happens
for stdcall even with extern "C": an appended @<n> where <n> is the number of
bytes the parameters occupy on the stack.

> P.S. At the risk of being accused of cross-posting, do you happen to
> know how to get the linker to drop those pesky underscores?

You can eliminate any kind of mangling by using a DEF file instead of
(or in addition to) _declspec. In the DEF file you can explicitely give the
name you want exported.

Peter Below (TeamB) 10011...@compuserve.com)


Brian Paisley

unread,
Jun 10, 1998, 3:00:00 AM6/10/98
to

On Wed, 10 Jun 1998 11:42:40 +0200, Peter Below
<10011...@compuserve.com> wrote:

>You can eliminate any kind of mangling by using a DEF file instead of
>(or in addition to) _declspec. In the DEF file you can explicitely give the
>name you want exported.

Thanks for the info as well as for the clarification on name mangling.

Regards,
Brian


0 new messages