[plt-scheme] foreign.ss dll path

From: Yoav Goldberg (yoav.goldberg at gmail.com)
Date: Sat Oct 15 19:14:37 EDT 2005

Thanks for the pointers, I'll give it a shot later tonight!

On 10/15/05, Daniel Pinto de Mello e Silva <daniel.silva at gmail.com> wrote:
> I think the Scheme current-directory parameter only changes the
> interpreter's view of what the current working directory is.  To
> change the working directory of the process and the libraries it
> loads, try the chdir function from the C runtime.  For Windows, look
> at
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__chdir.2c_._wchdir.asp
>
> For UNIX (POSIX), look at
>
> http://www.umbi.umd.edu/cgi-bin/man-cgi?chdir+2
>
> You'll also want to import the getcwd function.  For Linux, you don't
> need to preallocate a buffer, but you do need to specify a maximum
> path length:
>
> http://linux.wku.edu/cgi-bin/man2html?getcwd+3
>
> Here's an example:
>
> > (require (lib "foreign.ss"))
> > (unsafe!)
> > (define rt (ffi-lib #f))
> > (define chdir (get-ffi-obj "chdir" rt (_fun _string -> _int)))
> > (define getcwd (get-ffi-obj "getcwd" rt (_fun (_pointer = #f) (_int = 1024) -> _string)))
> > (getcwd)
> "/home/dsilva"
> > (chdir "/tmp")
> 0
> > (getcwd)
> "/tmp"
> > (current-directory)
> #<path:/home/dsilva>
> > (define (with-c-dir path thunk)
>    (define cwd (getcwd))
>    (dynamic-wind (lambda () (chdir path))
>                  thunk
>                  (lambda () (chdir cwd))))
> > (with-c-dir "/usr"
>     (lambda () (printf "Do some work in ~a~n" (getcwd))))
> Do some work in /usr
> > (getcwd)
> "/tmp"
>
> Daniel
>
> On 10/14/05, Yoav Goldberg <yoav.goldberg at gmail.com> wrote:
> > That was fast!
> >
> > It's working! great!
> >
> > But the damn dll tries to look for an .ini file ;-(
> >
> > (oof, this is annoying)
> >
> >
> > On 10/15/05, Eli Barzilay <eli at barzilay.org> wrote:
> > > On Oct 15, Yoav Goldberg wrote:
> > > > Thanks!
> > > >
> > > > I used (this-expression-source-directory), and that almost worked -
> > > > (ffi-lib ...) finds the dll, but unfortunately, the dll tries to load
> > > > *another* dll in the same directory. Do you have any idea how I can
> > > > get around that?
> > >
> > > Load the other dll yourself.  (Define it as some new ffi-lib, even
> > > when you don't use it.)
> > >
> > > --
> > >          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
> > >                  http://www.barzilay.org/                 Maze is Life!
> > >
> > >
> > _________________________________________________
> >   For list-related administrative tasks:
> >   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
>
>


Posted on the users mailing list.