starlet2003 发表于 2009-4-22 00:08:00

lisp可以读写二进制文件吗?

<p>想问一下,使用ALisp或者VLisp可以读写二进制文件吗?</p><p>如果可以,哪里有这样的范例呢?</p>

liu_kunlun 发表于 2009-4-22 08:44:00

这个问题还是比较重要的,但Lisp不可以。哪位高手想点办法?例如用Activex方法?

nonsmall 发表于 2009-4-22 09:15:00

<p>方法1:使用ActiveX</p><p>方法2:调用WIN32 API</p><p>方法3:利用VBA表达式</p>

highflybir 发表于 2009-4-22 09:32:00

下面提供一个函数。
(defun _ReadStream ( path len / fso file stream result )
    ;;If the file is successful read the data is returned as
    ;;a string. Won't be tripped up by nulls, control chars
    ;;including ctrl z (eof marker). Pretty fast (feel free
    ;;to bench mark / compare to alternates).
    ;;
    ;;If the caller wants the result as a list of byte values
    ;;simply use vl-string->list on the result:
    ;;
    ;;      (setq bytes
    ;;          (if (setq stream (_ReadStream path len))
    ;;            (vl-string->list stream)
    ;;          )
    ;;      )
    ;;
    ;;Arguments:
    ;;
    ;;      path<duh>
    ;;      len   Number of bytes to read. If non numeric, less
    ;;            than 1 or greater than the number of bytes in
    ;;            the file everything is returned.
    (vl-catch-all-apply
       '(lambda ( / iomode format size )
            (setq
                iomode1 ;; 1 = read,   2 = write,    8 = append
                format0 ;; 0 = ascii, -1 = unicode, -2 = system default
                fso   (vlax-create-object "Scripting.FileSystemObject")
                file    (vlax-invoke fso 'GetFile path)
                stream(vlax-invoke fso 'OpenTextFile path iomode format)
                size    (vlax-get file 'Size)
                len   (if (and (numberp len) (< 0 len size)) (fix len) size)
                result(vlax-invoke stream 'read len)
            )
            (vlax-invoke stream 'Close)
      )
    )
    (if stream (vlax-release-object stream))
    (if file (vlax-release-object file))
    (if fso (vlax-release-object fso))
    result
)
有空的话,楼主不妨上www.theswamp.org搜搜看,能得到很多方面的这样的程序。

starlet2003 发表于 2009-4-22 12:29:00

本帖最后由 作者 于 2009-6-11 14:48:06 编辑 <br /><br /> <p>谢谢楼上这位大哥</p>

我爱lisp 发表于 2016-2-19 16:15:24

没有用过,可以先顶一下楼上

hunkmax 发表于 2016-2-22 14:37:44

留个记号,以后有用,感谢感谢
页: [1]
查看完整版本: lisp可以读写二进制文件吗?