comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@acm.org>
Subject: Re: linking problem in DPAPI
Date: Sat, 31 Dec 2005 07:56:27 -0500
Date: 2005-12-31T07:56:27-05:00	[thread overview]
Message-ID: <upsndbf2c.fsf@acm.org> (raw)
In-Reply-To: dp2bqc$hn5$1@netnews.hinet.net

"bubble" <bubble@riskm.com.tw> writes:

> <copy from 
> http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/gnu-linker/win32.html>
>
> direct linking to a dll
> The cygwin/mingw ports of ld support the direct linking, including data 
> symbols, to a dll without the usage of any import libraries. 

Interesting. 

> after some error.
> I have a solution.
>
> I copy crypt32.dll from c:\windows\system32 to project home.
> and change pragma  (not use Stdcall Calling Convention ).
> pragma Import (C, CryptProtectData, "CryptProtectData");
> then it work..

As you discover below, "linking" is not the same as "working".

> I have new question..
> in windows SDK document ,the WINAPI declare should mapping to Stdcall.
> It's mean who's responsibility to clean stack frame.
> http://www.unixwiz.net/techtips/win32-callconv.html
> if I use "C" calling conventions in a "WINAPI" funciton , colud system clean 
> stack twice and cause some problems?

Yes, you will eventually get a stack error; either overflow or underflow.

The problem is that the 'Convention' parameter in 'pragma Import'
speficies two things; the 'calling convention' (who pops the stack),
and the 'naming convention' (how the name is mangled in the DLL).

Microsoft has two naming conventions for the StdCall calling
convention; the 'old' one (pre Windows NT) that appends '@nn' where
'nn' is the number of bytes on the stack, and the 'new' one without
the @nn.

Ada has no way to distinguish between the two. A while ago (May 2004)
I had a similar problem, and tried to get AdaCore to provide a
Convention identifier for the 'new' StdCall naming convention; they
didn't believe it was necessary.

On the other hand, the "Link_Name" parameter to 'pragma Import' should
allow you to specify the correct name. In 2004 (GNAT 3.15?) the
compiler added '@nn' even to the Link_Name; AdaCore promised to fix
that.

So you should try using:

    pragma Import (StdCall, CryptProtectData, 
         External_Name => "CryptProtectData", 
         Link_Name => "CryptProtectData");

If that doesn't work, you'll have to build an import library that uses
the StdCall calling convention with the new naming convention. That is
done via the following steps (as recommended by AdaCore):

dll2def crypt32.dll > crypt32.def

_manually_ edit cyrpt32.def to add the appropriate @nn. 
(this step is just ridiculous, but it is required by the GNAT tools).

gnatdll -k -e cryp32.def -d crypt32.dll

The -k strips the @nn that you so laboriously added in the previous
step. Hmm. I guess that means the 'nn' in the .def doesn't have to be
correct; it just has to be there.

Hmm. I've just re-read the GNAT user's guide for 5.03a. It says GNAT
can use the .lib library files (Microsoft format). It also gives the
procedure I outlined above. 

However, my GNAT distribution doesn't contain dll2def. I found a
version (via Google) at
http://users.ncrvnet.nl/gmvdijk/packages.html#DLL2DEF
Hmm. That has source code; maybe we could fix it to add an option to
add the @nn.

In any case, send a bug report to AdaCore. Let them know how hard it
is to use their tools to do what should be a simple task. Maybe
they'll fix it eventually! Mention my bug report D525-020; that will
let them know it's not an isolated case.

Also ask how they build libcrypt32.a; I can't believe they manually
edit a .def file!

-- 
-- Stephe



  reply	other threads:[~2005-12-31 12:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-28  9:15 linking problem in DPAPI bubble
2005-12-28 12:28 ` Stephen Leake
2005-12-29  4:19   ` bubble
2005-12-29 13:39     ` Jeffrey Creem
2005-12-29 21:38     ` Stephen Leake
2005-12-30  4:07       ` bubble
2005-12-31 12:56         ` Stephen Leake [this message]
2005-12-31 14:32           ` Pascal Obry
2006-01-03  7:10         ` bubble
2006-01-03 11:22           ` Stephen Leake
2005-12-29  6:23   ` bubble
2005-12-29 21:37     ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox