* Help with GNAT, WinNT, StdCall, dll, exported names
@ 2001-10-11 11:26 Peter Hend�n
2001-10-11 11:44 ` David Botton
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Peter Hend�n @ 2001-10-11 11:26 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1040 bytes --]
I'm using gnat 3.13p, trying to build a dll that exports functions
that are to be called by a windows service. The problem is
that the functions are declared in the .h file as
BOOL WINAPI Foobar(LPFUNNY_STRUCT fum);
Now I have defined an Ada function for this, and
it works fine when I export it as
pragma Export(C, Foobar, "Foobar");.
Of course this will be called exactly once, because
it is the wrong calling convention, and after its return
the stack is fubar.
When I try to declare it StdCall instead of C, I am
not able to link it. Whatever I put in the .DEF file
it comes out wrong. I get from the last gnatlink step
in gnatdll:
mydll.exp(.edata+0x34):fake: undefined reference to `Foobar'
I have tried everything in the gnat user's guide, searched
this groups archive and generally banged my head against
the wall in appropriate - and perhaps not so appropriate -
ways. Please help!
/Peter H.
--
Peter Hend�n http://www.algonet.se/~phenden
ICQ: 14672398
Teknisk Dokumentation AB http://www.tdab.com
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Help with GNAT, WinNT, StdCall, dll, exported names
2001-10-11 11:26 Help with GNAT, WinNT, StdCall, dll, exported names Peter Hend�n
@ 2001-10-11 11:44 ` David Botton
2001-10-11 16:06 ` Peter Hend�n
2001-10-11 13:28 ` Stephen Leake
2001-10-11 17:59 ` Sergey Koshcheyev
2 siblings, 1 reply; 11+ messages in thread
From: David Botton @ 2001-10-11 11:44 UTC (permalink / raw)
To: comp.lang.ada
Why would you use a DLL for this? Creating a simple Ada COM object is easier
to do in Ada and easier to use in C++!
See the tutorial in GNATCOM for a detailed basic example (should be enough
to get you started). In summary:
1. Create the IDL for your Ada based COM object and compile with midl.exe
from VC++
2. Run CreateCOM on the TLB that is created by midl.exe
3. Fill in the blanks in the Ada code!!
4. Compile and register object
On the C++ side use #import "XXXX.dll" where XXXX.dll is the Ada COM object
dll created above.
MyInterfacePtr X;
X.Create (__uuidof(MyObject));
X->DoMyStuff ();
X = NULL;
Done.
http://www.adapower.com/gnatcom
David Botton
----- Original Message -----
From: "Peter Hend�n" <phenden@tdab.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Thursday, October 11, 2001 7:26 AM
Subject: Help with GNAT, WinNT, StdCall, dll, exported names
> I'm using gnat 3.13p, trying to build a dll that exports functions
> that are to be called by a windows service. The problem is
> that the functions are declared in the .h file as
>
> BOOL WINAPI Foobar(LPFUNNY_STRUCT fum);
>
> Now I have defined an Ada function for this, and
> it works fine when I export it as
> pragma Export(C, Foobar, "Foobar");.
>
> Of course this will be called exactly once, because
> it is the wrong calling convention, and after its return
> the stack is fubar.
>
> When I try to declare it StdCall instead of C, I am
> not able to link it. Whatever I put in the .DEF file
> it comes out wrong. I get from the last gnatlink step
> in gnatdll:
>
> mydll.exp(.edata+0x34):fake: undefined reference to `Foobar'
>
> I have tried everything in the gnat user's guide, searched
> this groups archive and generally banged my head against
> the wall in appropriate - and perhaps not so appropriate -
> ways. Please help!
>
> /Peter H.
>
> --
> Peter Hend�n http://www.algonet.se/~phenden
> ICQ: 14672398
> Teknisk Dokumentation AB http://www.tdab.com
>
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Help with GNAT, WinNT, StdCall, dll, exported names
2001-10-11 11:26 Help with GNAT, WinNT, StdCall, dll, exported names Peter Hend�n
2001-10-11 11:44 ` David Botton
@ 2001-10-11 13:28 ` Stephen Leake
2001-10-11 16:23 ` Peter Hend�n
2001-10-11 19:24 ` David Botton
2001-10-11 17:59 ` Sergey Koshcheyev
2 siblings, 2 replies; 11+ messages in thread
From: Stephen Leake @ 2001-10-11 13:28 UTC (permalink / raw)
"Peter Hend�n" <phenden@tdab.com> writes:
> I'm using gnat 3.13p, trying to build a dll that exports functions
> that are to be called by a windows service. The problem is
> that the functions are declared in the .h file as
>
> BOOL WINAPI Foobar(LPFUNNY_STRUCT fum);
>
> Now I have defined an Ada function for this, and
> it works fine when I export it as
> pragma Export(C, Foobar, "Foobar");.
>
> Of course this will be called exactly once, because
> it is the wrong calling convention, and after its return
> the stack is fubar.
>
> When I try to declare it StdCall instead of C, I am
> not able to link it. Whatever I put in the .DEF file
> it comes out wrong. I get from the last gnatlink step
> in gnatdll:
>
> mydll.exp(.edata+0x34):fake: undefined reference to `Foobar'
>
> I have tried everything in the gnat user's guide, searched
> this groups archive and generally banged my head against
> the wall in appropriate - and perhaps not so appropriate -
> ways. Please help!
You don't mention what C compiler you are using. I have found that
different C compilers (and different Ada compilers) have different
naming conventions, usually having to do with prepending and
underscore. Here's my matrix:
compiler calling function link DLL
convention name name name
Borland C++ Cdecl foo _foo _foo
stdcall foo foo foo
Borland C Cdecl foo _foo _foo
stdcall foo foo foo
GNAT Ada C foo _foo foo
(stdcall not supported in DLLs)
Gnu C C foo _foo foo
ObjectAda
Ada DLL_Cdecl foo _foo foo
DLL_Stdcall foo _foo foo
I also have this note:
Since GNAT Ada does not support the stdcall convention for DLLs, we
use the Cdecl convention everywhere.
That was true for 3.12, apparently it's not true anymore.
Hope this helps!
--
-- Stephe
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Help with GNAT, WinNT, StdCall, dll, exported names
2001-10-11 11:44 ` David Botton
@ 2001-10-11 16:06 ` Peter Hend�n
2001-10-11 19:03 ` David Botton
0 siblings, 1 reply; 11+ messages in thread
From: Peter Hend�n @ 2001-10-11 16:06 UTC (permalink / raw)
"David Botton" wrote:
<snipped good reply - but was not really my problem>
David, I do not have the luxury of using COM objects, which
is of course the best (IMHO) solution - if it is possible.
In this case I have a server that expects to load my dll, and
then call the entry points of that dll using the StdCall convention.
Any solutions?
/Peter H.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Help with GNAT, WinNT, StdCall, dll, exported names
2001-10-11 13:28 ` Stephen Leake
@ 2001-10-11 16:23 ` Peter Hend�n
2001-10-11 19:24 ` David Botton
1 sibling, 0 replies; 11+ messages in thread
From: Peter Hend�n @ 2001-10-11 16:23 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 745 bytes --]
"Stephen Leake" wrote:
> You don't mention what C compiler you are using. I have found that
> different C compilers (and different Ada compilers) have different
> naming conventions, usually having to do with prepending and
> underscore. Here's my matrix:
Yes, the problem is related to prefixing with _ and suffixing with @nn,
but the service that uses my dll, expects the name Foobar, without
any pre- or suffix. I can easily accmplish this with the C convention,
but it seems impossible with the StdCall convention.
Please note that I have no control whatsoever over how my dll
is called.
Thanks,
Peter H.
--
Peter Hend�n http://www.algonet.se/~phenden
ICQ: 14672398
Teknisk Dokumentation AB http://www.tdab.com
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Help with GNAT, WinNT, StdCall, dll, exported names
2001-10-11 11:26 Help with GNAT, WinNT, StdCall, dll, exported names Peter Hend�n
2001-10-11 11:44 ` David Botton
2001-10-11 13:28 ` Stephen Leake
@ 2001-10-11 17:59 ` Sergey Koshcheyev
2 siblings, 0 replies; 11+ messages in thread
From: Sergey Koshcheyev @ 2001-10-11 17:59 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 684 bytes --]
"Peter Hend�n" <phenden@tdab.com> wrote in message
news:%lfx7.6$_o6.503@newsc.telia.net...
> <snip>
> When I try to declare it StdCall instead of C, I am
> not able to link it. Whatever I put in the .DEF file
> it comes out wrong. I get from the last gnatlink step
> in gnatdll:
>
> mydll.exp(.edata+0x34):fake: undefined reference to `Foobar'
Have you tried specifying the link name in the pragma? Something like this:
pragma Export (Stdcall, Foobar, "Foobar", Link_Name => "Foobar");
may work (not tested).
> <snip>
> --
> Peter Hend�n http://www.algonet.se/~phenden
> ICQ: 14672398
> Teknisk Dokumentation AB http://www.tdab.com
Sergey Koshcheyev.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Help with GNAT, WinNT, StdCall, dll, exported names
2001-10-11 16:06 ` Peter Hend�n
@ 2001-10-11 19:03 ` David Botton
0 siblings, 0 replies; 11+ messages in thread
From: David Botton @ 2001-10-11 19:03 UTC (permalink / raw)
To: comp.lang.ada
The key to fixing this is in the .def files. For example a def file
generated by CreateCOM:
EXPORTS
DllGetClassObject=DllGetClassObject@12 @2
DllCanUnloadNow=DllCanUnloadNow@0 @3
DllRegisterServer=DllRegisterServer@0 @4
DllUnregisterServer=DllUnregisterServer@0 @5
ExternalName=WhatNameUnderstood@SizeOfParameters @DllOrdinal
David Botton
----- Original Message -----
From: "Peter Hend�n" <phenden@tdab.com>
> In this case I have a server that expects to load my dll, and
> then call the entry points of that dll using the StdCall convention.
>
> Any solutions?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Help with GNAT, WinNT, StdCall, dll, exported names
2001-10-11 13:28 ` Stephen Leake
2001-10-11 16:23 ` Peter Hend�n
@ 2001-10-11 19:24 ` David Botton
2001-10-11 23:28 ` Peter Hend�n
1 sibling, 1 reply; 11+ messages in thread
From: David Botton @ 2001-10-11 19:24 UTC (permalink / raw)
To: comp.lang.ada
I don't know how true that is. I used STDCALL convention functions in DLLs
with GNAT 3.12p
David Botton
----- Original Message -----
From: "Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov>
> Since GNAT Ada does not support the stdcall convention for DLLs, we
> use the Cdecl convention everywhere.
>
> That was true for 3.12, apparently it's not true anymore.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Help with GNAT, WinNT, StdCall, dll, exported names
2001-10-11 19:24 ` David Botton
@ 2001-10-11 23:28 ` Peter Hend�n
2001-10-11 23:46 ` David Botton
0 siblings, 1 reply; 11+ messages in thread
From: Peter Hend�n @ 2001-10-11 23:28 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 473 bytes --]
David Botton wrote:
> I don't know how true that is. I used STDCALL convention functions in DLLs
> with GNAT 3.12p
Did you Export them? In that case, could you give me some samples of
function declarations, pragmas, .DEF file and the command line switches
you gave to gnatdll/link/bind etc. Any help at all would be appreciated.
/Peter H.
--
Peter Hend�n http://www.algonet.se/~phenden
ICQ: 14672398
Teknisk Dokumentation AB http://www.tdab.com
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Help with GNAT, WinNT, StdCall, dll, exported names
2001-10-11 23:28 ` Peter Hend�n
@ 2001-10-11 23:46 ` David Botton
2001-10-12 9:48 ` Peter Hend�n
0 siblings, 1 reply; 11+ messages in thread
From: David Botton @ 2001-10-11 23:46 UTC (permalink / raw)
To: comp.lang.ada
Take a look at GNATCOM.Create.Inproc.ads
http://www.adapower.com/gnatcom/src/gnatcom-create-inproc__ads.htm
David Botton
----- Original Message -----
From: "Peter Hend�n" <phenden@tdab.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Thursday, October 11, 2001 7:28 PM
Subject: Re: Help with GNAT, WinNT, StdCall, dll, exported names
> David Botton wrote:
> > I don't know how true that is. I used STDCALL convention functions in
DLLs
> > with GNAT 3.12p
>
> Did you Export them? In that case, could you give me some samples of
> function declarations, pragmas, .DEF file and the command line switches
> you gave to gnatdll/link/bind etc. Any help at all would be appreciated.
>
> /Peter H.
>
> --
> Peter Hend�n http://www.algonet.se/~phenden
> ICQ: 14672398
> Teknisk Dokumentation AB http://www.tdab.com
>
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Help with GNAT, WinNT, StdCall, dll, exported names
2001-10-11 23:46 ` David Botton
@ 2001-10-12 9:48 ` Peter Hend�n
0 siblings, 0 replies; 11+ messages in thread
From: Peter Hend�n @ 2001-10-12 9:48 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 471 bytes --]
David Botton wrote:
> Take a look at GNATCOM.Create.Inproc.ads
> http://www.adapower.com/gnatcom/src/gnatcom-create-inproc__ads.htm
Thanx a million, David. The answer was actually already om my machine.
I should have looked in the GNATCom docs from the start. The secret
was in the .DEF file, ie. name mangling.
Thanks again,
Peter H.
--
Peter Hend�n http://www.algonet.se/~phenden
ICQ: 14672398
Teknisk Dokumentation AB http://www.tdab.com
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2001-10-12 9:48 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-11 11:26 Help with GNAT, WinNT, StdCall, dll, exported names Peter Hend�n
2001-10-11 11:44 ` David Botton
2001-10-11 16:06 ` Peter Hend�n
2001-10-11 19:03 ` David Botton
2001-10-11 13:28 ` Stephen Leake
2001-10-11 16:23 ` Peter Hend�n
2001-10-11 19:24 ` David Botton
2001-10-11 23:28 ` Peter Hend�n
2001-10-11 23:46 ` David Botton
2001-10-12 9:48 ` Peter Hend�n
2001-10-11 17:59 ` Sergey Koshcheyev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox