1. ;;by tryhi http://bbs.mjtd.com/forum.php?mod=viewthread&tid=182474&highlight=%CF%C2%D4%D8
    2. (vl-Load-COM)
    3. (defun try-file-ReadBinary (FileName / node size str stream xmldom)
    4. (setq xmldom (vlax-create-object "Microsoft.XMLDOM"))
    5. (setq node (vlax-invoke-method xmldom 'CreateElement "binary"))
    6. (vlax-put-Property node 'DataType "bin.hex")
    7. (setq stream (vlax-create-object "ADODB.Stream"))
    8. (vlax-put-Property stream 'type 1)
    9. (Vlax-Invoke stream 'open)
    10. (vlax-invoke-method
    11. stream
    12. 'LoadFromFile
    13. FileName
    14. )
    15. (setq size(vlax-get-Property stream 'size))
    16. (vlax-put-Property node 'NodeTypedValue (Vlax-Invoke-Method stream 'Read size))
    17. (Vlax-Invoke-Method stream 'close)
    18. (setq str (vlax-get-Property node 'text))
    19. (vlax-release-object xmldom)
    20. str
    21. )
    22. (defun try-file-WriteBinary (file str / node stream xmldom)
    23. (setq xmldom (vlax-create-object "Microsoft.XMLDOM"))
    24. (setq node (vlax-invoke-method xmldom 'CreateElement "binary"))
    25. (vlax-put-Property node 'DataType "bin.hex")
    26. (vlax-put-Property node 'Text str)
    27. (setq stream (vlax-create-object "ADODB.Stream"))
    28. (vlax-put-Property stream 'type 1)
    29. (Vlax-Invoke stream 'open)
    30. (vlax-invoke-method stream 'write
    31. (vlax-get-Property node 'NodeTypedValue)
    32. )
    33. (vlax-invoke-method stream 'saveToFile file 2)
    34. (Vlax-Invoke-Method stream 'close)
    35. (vlax-release-object xmldom)
    36. (vlax-release-object stream)
    37. )
    38. (defun c:tt (/ file h16 h16-2 newfile)
    39. (setq file(getfiled "选择一个文件" "" "*" 0))
    40. (or file (exit))
    41. (setq
    42. h16(try-file-ReadBinary file)
    43. h16-2(substr h16 5)
    44. )
    45. (setq newfile (strcat(vl-filename-directory file)"\\"(vl-filename-base file)"_new"(vl-filename-extension file)))
    46. (try-file-WriteBinary newfile h16-2)
    47. (princ(strcat"\n处理完成,生成新文件"newfile))(princ)
    48. )