在Ubuntu
我在OCaml的編碼非常簡單ml.ml
:呼叫OCaml中的可執行文件或C從VBA代碼
let() = print_string "hello world, in OCaml\n"
而且在C簡單c.c
:
#include <stdio.h>
main() {
printf("hello world, in C\n");
return 0; }
然後我編譯它通過ocamlc -o mlexe.exe ml.ml
和gcc -o cexe.exe c.c
。在Ubuntu
的終端下啓動mlexe.exe
或cexe.exe
會返回字符串。
現在我想從VBA代碼中調用它。我啓動Windows,打開Microsoft Excel文件,和VBA編輯器,並提出:
Sub run()
Dim ProcID As Integer
ProcID = Shell("C:\Windows\system32\calc.exe", 1)
Dim Result As Variant
Result = Shell("C:\test\cexe.exe",1)
'Result = Shell("C:\test\mlexe.exe",1)
'Result = Shell("C:\test\cexe.exe")
'Result = Shell("C:\test\mlexe.exe")
End Sub
我希望Result
得到字符串hello world...
(或在一個不太好的情況下退出代碼),運行宏不啓動計算器,但給我一個錯誤Run-time error '5': Invalid procedure call or argument
,其他4 Shell
與我自己的可執行文件。
目標只是調用由VBA代碼中另一種語言自己編譯的可執行文件。
誰能告訴我什麼是錯?
如果使用本地編譯器'ocamlopt'而不是字節碼編譯器'ocamlc'來產生程序,會發生什麼?我認爲這可能會更簡單。否則,由於'hello.exe'實際上是一個字節碼文件,所以你可以嘗試運行'ocamlrun.exe hello.exe' – 2012-07-25 18:48:49
ocaml程序是否真的*返回*字符串或只是*打印*它?我想後者。 – phimuemue 2012-07-25 18:51:23
@PascalCuoq:我嘗試過'ocamlopt',並得到同樣的錯誤。我嘗試了'Result = Shell(「」「ocamlrun.exe」「C:\ test \ hello.exe」)',並且它返回'File not found'。 – SoftTimur 2012-07-25 19:03:32