- 积分
- 15216
- 明经币
- 个
- 注册时间
- 2008-8-21
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2011-11-8 17:58:30
|
显示全部楼层
highflybir 发表于 2011-11-8 12:11
你把生成的二进制字符串作为一个字符串变量就可以了啊。
但是要提醒的一点是:
如果字符串太长,LISP不 ...
我的意思是象下面函数,我将filename当作一个字符变量而不是一个文件名和路径,
stream.LoadFromFile FileName 改为stream.writetext stringi得不到返回二进制值
本意是想将文本变成二进制,不用写到文件后再读再转换。
另外的WriteBinary函数,我不要它写至文件中去,是希望它将二进制流转回文本,改了试过也不行,
请版主指点
(defun ReadBinary (string / str wsObj)
(if (setq wsObj (vlax-create-object "ScriptControl"))
(progn
(vlax-put wsObj "language" "VBS")
(setq str
"Function ReadBinary(string)
Const adTypeBinary = 1这个改文本格式也不行
Dim stream, xmldom, node
Set xmldom = CreateObject(\"Microsoft.XMLDOM\")
Set node = xmldom.CreateElement(\"binary\")
node.DataType = \"bin.hex\"
Set stream = CreateObject(\"ADODB.Stream\")
stream.Type = adTypeBinary
stream.Open
stream.LoadFromFile FileName 改为stream.writetext string
node.NodeTypedValue = stream.Read
stream.Close
Set stream = Nothing
ReadBinary = node.Text
Set node = Nothing
Set xmldom = Nothing
End Function"
)
(vlax-invoke wsObj 'ExecuteStatement str)
(setq str (vlax-invoke wsObj 'run "ReadBinary" string))
(vlax-release-object wsObj)
str
)
)
)
(defun WriteBinary (buffer / wsObj str)
(if (setq wsObj (vlax-create-object "ScriptControl"))
(progn
(vlax-put wsObj "language" "VBS")
(setq str
"Function WriteBinary(Buf)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Dim stream, xmldom, node
Set xmldom = CreateObject(\"Microsoft.XMLDOM\")
Set node = xmldom.CreateElement(\"binary\")
node.DataType = \"bin.hex\"
node.Text = Buf
Set stream = CreateObject(\"ADODB.Stream\")
stream.Type = adTypeBinary
stream.Open
stream.write node.NodeTypedValue
;stream.saveToFile FileName, adSaveCreateOverWrite去了这句
stream.Close
Set stream = Nothing
WriteBinary=node.Text加上这句
Set node = Nothing
Set xmldom = Nothing
End Function"
)
(vlax-invoke wsObj 'ExecuteStatement str)
(setq str(vlax-invoke wsObj 'run "WriteBinary" buffer))
(vlax-release-object wsObj)
str
)
)
)
|
|