comp.lang.ada
 help / color / mirror / Atom feed
From: AndreiK <andrei.krivoshei@gmail.com>
Subject: Re: Directory Operations
Date: Tue, 4 Nov 2008 04:57:17 -0800 (PST)
Date: 2008-11-04T04:57:17-08:00	[thread overview]
Message-ID: <e6361d57-d505-433f-a031-dd9c90961c98@c22g2000prc.googlegroups.com> (raw)
In-Reply-To: 1b1xmaowns246.x8v3yiu0yo6g.dlg@40tude.net

On 3 нояб, 19:33, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On Mon, 3 Nov 2008 08:27:36 -0800 (PST), andrei.krivos...@gmail.com wrote:
> > I have a problem.
> > I need to write a DLL with a function, which returns the path to a
> > current directory under Windows XP.
> > I have't any problem with DLL itself, but when I try to use some
> > function from the package "GNAT.Directory_Operations" or
> > "Ada.Directories", I get the unexecutable DLL.
> > NOTE! The executable file is working, I talk only about DLL variant!
>
> > Thanks!
>
> > The code listing of my program is
>
> > ========= Spec ============
> > with Interfaces.C.Strings; use Interfaces.C.Strings;
>
> > package FAD is
>
> >    procedure Pwd(Path_ptr: in out Chars_ptr );
>
> 1. Why don't you use Ada convention returning plain String?
>
>    function Pwd return String
>   [   renames Ada.Directories.Current_Directory; -- Work is done ]
>

Thank you for this advice.

> 2. Should you keep it non-Ada, then
>
> 2.a. how is this supposed to work?
> 2.b. Where is the string allocated?
> 2.c. Who will dispose it? When?
> 2.d. What happens when called from multiple threads?
>
>

Yes I have to keep it in non-Ada, more exact I have to use it in the
"NI LabVIEW"
2.a The LabVIEW calls the functions from DLL.
2.b,c LabVIEW allocates the string.
2.d --- I don't now

May be I can use plain String instead of pointers, but it seems, that
the problem is more abstract from the problem of String
representation.
For readability I will describe it in the next message.

> >    pragma Export(C, Pwd, "pwd");
>
> > end FAD;
>
> > ========= Body ============
> > --  with Ada.Directories;
> > with Ada.Strings;
> > with GNAT.Directory_Operations;
>
> > package body FAD is
> >    package DOP renames GNAT.Directory_Operations;
> >    use Ada.Strings;
>
> >    procedure Pwd(Path_ptr: in out Chars_ptr ) is
> > --        use Ada.Directories;
> >       CStr: Chars_ptr;
> >       Path: String (1 .. 1024);
> >    begin
> > --      Path: String := "custom test string";  -- with this code line,
> > the DLL is executable
> >       Path := DOP.Get_Current_Dir;  -- with this code line, the DLL is UNexecutable
>
> This cannot work, since Get_Current_Dir'Length may differ from 1024.
>
> >       CStr := Null_Ptr; -- Value for test purposes only
> >       Path_ptr := CStr;
>
> That will not work either because Path is allocated on the stack and
> destroyed upon return. See questions 2.a-d.
>
> >    end Pwd;
>
> > end FAD;
>
> C programming is substantially more difficult, even if occasionally spelt
> in Ada...
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de

Thank you!



  reply	other threads:[~2008-11-04 12:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-03 16:27 Directory Operations andrei.krivoshei
2008-11-03 17:33 ` Dmitry A. Kazakov
2008-11-04 12:57   ` AndreiK [this message]
2008-11-04 14:44     ` Dmitry A. Kazakov
2008-11-04 13:52 ` AndreiK
replies disabled

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