From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f91205dad8b4d2db X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!c22g2000prc.googlegroups.com!not-for-mail From: AndreiK Newsgroups: comp.lang.ada Subject: Re: Directory Operations Date: Tue, 4 Nov 2008 04:57:17 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <91990db2-68b4-4710-ba9b-b3a9d8375cad@e38g2000prn.googlegroups.com> <1b1xmaowns246.x8v3yiu0yo6g.dlg@40tude.net> NNTP-Posting-Host: 193.40.240.135 Mime-Version: 1.0 Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1225803437 30788 127.0.0.1 (4 Nov 2008 12:57:17 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 4 Nov 2008 12:57:17 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c22g2000prc.googlegroups.com; posting-host=193.40.240.135; posting-account=kfQcmwoAAAAImQIpF8z0neulU3uSEwPV User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8292 Date: 2008-11-04T04:57:17-08:00 List-Id: On 3 =CE=CF=D1=C2, 19:33, "Dmitry A. Kazakov" 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 > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D Spec =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > with Interfaces.C.Strings; use Interfaces.C.Strings; > > > package FAD is > > > =9A =9Aprocedure Pwd(Path_ptr: in out Chars_ptr ); > > 1. Why don't you use Ada convention returning plain String? > > =9A =9Afunction Pwd return String > =9A [ =9A 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. > > =9A =9Apragma Export(C, Pwd, "pwd"); > > > end FAD; > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D Body =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > -- =9Awith Ada.Directories; > > with Ada.Strings; > > with GNAT.Directory_Operations; > > > package body FAD is > > =9A =9Apackage DOP renames GNAT.Directory_Operations; > > =9A =9Ause Ada.Strings; > > > =9A =9Aprocedure Pwd(Path_ptr: in out Chars_ptr ) is > > -- =9A =9A =9A =9Ause Ada.Directories; > > =9A =9A =9A CStr: Chars_ptr; > > =9A =9A =9A Path: String (1 .. 1024); > > =9A =9Abegin > > -- =9A =9A =9APath: String :=3D "custom test string"; =9A-- with this c= ode line, > > the DLL is executable > > =9A =9A =9A Path :=3D DOP.Get_Current_Dir; =9A-- with this code line, t= he DLL is UNexecutable > > This cannot work, since Get_Current_Dir'Length may differ from 1024. > > > =9A =9A =9A CStr :=3D Null_Ptr; -- Value for test purposes only > > =9A =9A =9A Path_ptr :=3D CStr; > > That will not work either because Path is allocated on the stack and > destroyed upon return. See questions 2.a-d. > > > =9A =9Aend 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!