From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Directory Operations
Date: Mon, 3 Nov 2008 18:33:50 +0100
Date: 2008-11-03T18:33:53+01:00 [thread overview]
Message-ID: <1b1xmaowns246.x8v3yiu0yo6g.dlg@40tude.net> (raw)
In-Reply-To: 91990db2-68b4-4710-ba9b-b3a9d8375cad@e38g2000prn.googlegroups.com
On Mon, 3 Nov 2008 08:27:36 -0800 (PST), andrei.krivoshei@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 ]
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?
> 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. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2008-11-03 17:33 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 [this message]
2008-11-04 12:57 ` AndreiK
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