ekko Posted August 16, 2024 Posted August 16, 2024 I know that I can write the binary data of a .exe file into a txt file. My question is, can the binary data of the #<variant 8204 ...> variant also be written into a txt file? Quote
pkenewell Posted August 16, 2024 Posted August 16, 2024 @ekko It's very hard to determine what you want without any specific intention or code. But off the top of my head: have you looked into (vlax-variant-value)? https://help.autodesk.com/view/ACD/2025/ENU/index.html?guid=GUID-D26E25ED-6D9A-4E0F-B7C3-CC10F95246F9 Quote
ekko Posted August 16, 2024 Author Posted August 16, 2024 1 hour ago, pkenewell said: @ekko It's very hard to determine what you want without any specific intention or code. But off the top of my head: have you looked into (vlax-variant-value)? https://help.autodesk.com/view/ACD/2025/ENU/index.html?guid=GUID-D26E25ED-6D9A-4E0F-B7C3-CC10F95246F9 ;;-----------------=={ Read Binary Stream }==-----------------;; ;; ;; ;; Uses the ADO Stream Object to read a supplied file and ;; ;; returns a variant of bytes. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; filename - filename of file to read. ;; ;; len - number of bytes to read ;; ;; (if non-numerical, less than 1, or greater than the size ;; ;; of the file, everything is returned). ;; ;;------------------------------------------------------------;; ;; Returns: ;; ;; Variant of Binary data which may be converted to a list ;; ;; bytes using the relevant VL Variant functions or used ;; ;; with LM:WriteBinaryStream. ;; ;;------------------------------------------------------------;; (defun LM:ReadBinaryStream ( filename len / ADOStream result ) (vl-load-com) (setq result (vl-catch-all-apply (function (lambda ( / size ) (setq ADOStream (vlax-create-object "ADODB.Stream")) (vlax-invoke ADOStream 'Open) (vlax-put-property ADOStream 'type 1) (vlax-invoke-method ADOStream 'loadfromfile filename) (vlax-put-property ADOStream 'position 0) (setq size (vlax-get ADOStream 'size)) (vlax-invoke-method ADOStream 'read (if (and (numberp len) (< 0 len size)) (fix len) -1)) ) ) ) ) (if ADOStream (vlax-release-object ADOStream)) (if (not (vl-catch-all-error-p result)) result ) ) ;;-----------------=={ Write Binary Stream }==----------------;; ;; ;; ;; Uses the ADO Stream Object to write a variant of bytes to ;; ;; a specified file. File is created if non-existent or ;; ;; overwritten if found. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; filename - filename of file to read. ;; ;; data - variant of binary data to write to the file. ;; ;; (as returned by LM:ReadBinaryStream) ;; ;;------------------------------------------------------------;; ;; Returns: Filename of specified file, else nil. ;; ;;------------------------------------------------------------;; (defun LM:WriteBinaryStream ( filename data / ADOStream result ) (vl-load-com) (setq result (vl-catch-all-apply (function (lambda ( ) (setq ADOStream (vlax-create-object "ADODB.Stream")) (vlax-put-property ADOStream 'type 1) (vlax-invoke ADOStream 'open) (vlax-invoke-method ADOStream 'write data) (vlax-invoke ADOStream 'savetofile filename 2) ) ) ) ) (if ADOStream (vlax-release-object ADOStream)) (if (not (vl-catch-all-error-p result)) file ) ) Like this function LM:WriteBinaryStream ,But filename is a file, and I want to read the binary data of the variant. Quote
BIGAL Posted August 16, 2024 Posted August 16, 2024 Not sure what the end goal is and why, but did at some stage do a get and put of bytes. I may be wrong but is not a binary file made up of hex for each byte ? Look into DEBUG.exe. Quote
GLAVCVS Posted Wednesday at 10:39 PM Posted Wednesday at 10:39 PM Hi First of all, thank you LM for sharing this elegant and efficient code. I have used the read function before. However, the write function is difficult for me: I can't get the 'data' argument to be formatted properly. Has anyone managed to write anything that hasn't been read to another file with LM:ReadBinary...? Any examples? Thanks in advance Quote
GLAVCVS Posted Saturday at 08:25 AM Posted Saturday at 08:25 AM Ok I solved it. The problem was in the difference between 'vlax-invoke' and 'vlax-invoke-method' Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.