Thank-you for your reply.
The code you modified works, in the sense that it displays the proper
thing to the SBCL prompt, but it is curious that all c-string types are
being treated as (* char). Since the documentation for c-string explicitly
describes 16-bit external formats like :ucs-2 shouldn't a (c-string
:external-format :ucs-2) be something like a (* wchar) or (* short)?
Look further down in the message for the definition of
GetCurrentDirectoryW. If I modify the definition so that the compiler
doesn't complain, per your suggestion, I would have the following:
(define-alien-routine ("GetCurrentDirectoryW" GetCurrentDirectoryW)
(buffer (c-string :external-format :ucs-2)))
(defvar wbuf (make-alien short 256))
(with-alien ((wstring (c-string :external-format :ucs-2)
(cast wbuf (* char))))
(GetCurrentDirectoryW 256 wstring)
Now, executing this leads to an encoding error. SBCL doesn't seem to be
doing the natural thing with wide character strings.
> -----Original Message-----
> From: Nikodemus Siivola [mailto:nikodemus@...]
> Sent: Tuesday, June 03, 2008 12:43 AM
> To: Neil Haven
> Cc: sbcl-devel@...
> Subject: Re: [Sbcl-devel] (alien c-string) behavior
> On Mon, Jun 2, 2008 at 7:30 PM, Neil Haven
> <gneilhaven@...> wrote:
> > The following behavior is odd and unexpected (Windows/SBCL ver.1.0.17.)
> > and should probably either be clearly documented or repaired. It
> > the type system does not understand the nuances of c-strings. Or am I
> > confused?
> This is intentional. You must use eg. SB-ALIEN:CAST.
> (let ((foo (make-alien short 2)))
> (setf (deref foo 0) #x6b6f
> (deref foo 1) #x0)
> (with-alien ((foost (c-string :external-format :ascii)
> (cast foo (* char))))
> -- Nikodemus
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.