明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2907|回复: 6

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

[复制链接]
发表于 2009-4-22 00:08:00 | 显示全部楼层 |阅读模式

想问一下,使用ALisp或者VLisp可以读写二进制文件吗?

如果可以,哪里有这样的范例呢?

发表于 2009-4-22 08:44:00 | 显示全部楼层
这个问题还是比较重要的,但Lisp不可以。哪位高手想点办法?例如用Activex方法?
发表于 2009-4-22 09:15:00 | 显示全部楼层

方法1:使用ActiveX

方法2:调用WIN32 API

方法3:利用VBA表达式

发表于 2009-4-22 09:32:00 | 显示全部楼层
[Post=10]下面提供一个函数。
  1. (defun _ReadStream ( path len / fso file stream result )
  2.     ;;  If the file is successful read the data is returned as
  3.     ;;  a string. Won't be tripped up by nulls, control chars
  4.     ;;  including ctrl z (eof marker). Pretty fast (feel free
  5.     ;;  to bench mark / compare to alternates).
  6.     ;;
  7.     ;;  If the caller wants the result as a list of byte values
  8.     ;;  simply use vl-string->list on the result:
  9.     ;;
  10.     ;;      (setq bytes
  11.     ;;          (if (setq stream (_ReadStream path len))
  12.     ;;              (vl-string->list stream)
  13.     ;;          )
  14.     ;;      )
  15.     ;;
  16.     ;;  Arguments:
  17.     ;;
  18.     ;;      path  <duh>
  19.     ;;      len   Number of bytes to read. If non numeric, less
  20.     ;;            than 1 or greater than the number of bytes in
  21.     ;;            the file everything is returned.
  22.     (vl-catch-all-apply
  23.        '(lambda ( / iomode format size )
  24.             (setq
  25.                 iomode  1 ;; 1 = read,   2 = write,    8 = append
  26.                 format  0 ;; 0 = ascii, -1 = unicode, -2 = system default
  27.                 fso     (vlax-create-object "Scripting.FileSystemObject")
  28.                 file    (vlax-invoke fso 'GetFile path)
  29.                 stream  (vlax-invoke fso 'OpenTextFile path iomode format)
  30.                 size    (vlax-get file 'Size)
  31.                 len     (if (and (numberp len) (< 0 len size)) (fix len) size)
  32.                 result  (vlax-invoke stream 'read len)
  33.             )
  34.             (vlax-invoke stream 'Close)
  35.         )
  36.     )
  37.     (if stream (vlax-release-object stream))
  38.     (if file (vlax-release-object file))
  39.     (if fso (vlax-release-object fso))
  40.     result
  41. )
[/Post]
有空的话,楼主不妨上www.theswamp.org搜搜看,能得到很多方面的这样的程序。
 楼主| 发表于 2009-4-22 12:29:00 | 显示全部楼层
本帖最后由 作者 于 2009-6-11 14:48:06 编辑

谢谢楼上这位大哥

发表于 2016-2-19 16:15:24 | 显示全部楼层
没有用过,可以先顶一下楼上
发表于 2016-2-22 14:37:44 | 显示全部楼层
留个记号,以后有用,感谢感谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-20 20:01 , Processed in 0.188231 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表