I don't know COM but here's an attempt to guess what happened based on
the documentation.
On Tue, Oct 8, 2019 at 11:51 AM Scott Gudeman <
sdgu...@gmail.com> wrote:
>
> I am working on converting a powershell script to Racket that takes a Word XML document and saves it as PDF.
>
> In powershell, when I call Word's `Documents.Open` method I can just pass it the naked string as the file path without anything special done to it. In Racket, however, when I run the following code I get an error telling me the type is bad
>
> ```
> (define xml-document (string-append (path->string (path->complete-path (build-path (find-system-path 'orig-dir) "temp"))) "\\" tag ".xml"))
> (define pdf-document (string-append (path->string (simplify-path (path->complete-path (build-path 'up "formatted")) #t)) "\\" tag ".pdf"))
> (define word-instance (com-create-instance "Word.Application"))
> (define word-document (com-invoke (com-get-property word-instance "Documents") "Open" xml-document))
> (com-invoke book "ExportAsFixedFormat"
> pdf-document
> 17 com-omit com-omit com-omit com-omit com-omit com-omit com-omit com-omit
> 1)
> (com-invoke book "Close")
> (com-invoke word-instance "Quit")
> (com-release word-instance)
>
> ```
> This gives the following error on the line the **define word-document**
>
> > Open: expected argument of type <(opt (box any))>; given:
> > "...\\pdf_gen\\temp\\filename.xml"
>
>
> I am very confused by this as the documentation suggests that I should be able to plug in the path as a string, the error suggests otherwise?
>
Based on the message, the method expects a value whose type
description is '(opt (box any)). From 5.17.1.9, this means that this
is an optional, call-by-reference (probably means a pointer in C
sense) argument and that on Racket's side it expects the callee to
modify the argument. I'm wondering if this would work:
(define word-document (com-invoke (com-get-property word-instance
"Documents") "Open" (box xml-document)))
5.17.1.9 COM Types
https://docs.racket-lang.org/foreign/com-auto.html#%28part._com-types%29
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
racket-users...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/423334b3-607e-4041-b046-06528c0ea5d7%40googlegroups.com.