在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