-1

I have a VBScript, where I have a 2D array. From the VBScript I'd like to call an .exe, written in C++.

Can I pass this VBScript array to the .exe by commandline or somehow else? If yes, how, and how do I process it? ( An example would be great.)

If it is not possible, with a 2D array, but it is with a 1D array, it is also a solution too.

Thanks!

Update: Just to clarify: I don't wish to pass the items of the array, one by one. I want to call the exe only once passing the whole array somehow, and process it inside the exe.

Update2: The array contins only strings, and the host environment for the script is Windows Script Host. Creating any file on the hard drive is not an option unfortunately.

kampi
  • 2,362
  • 12
  • 52
  • 91
  • 1
    There are several options: a) command line parameters b) a file c) shared memory d) pipes, .... Totally depends on your use case what's the best method. – πάντα ῥεῖ May 03 '15 at 14:13
  • File is not an option. Command line would be the best, maybe shared memory would work too. But how do I do it? – kampi May 03 '15 at 14:15
  • For a command line solution, you would need to convert your array to ASCII, pass it in the command line, then have the C++ program convert it back to actual data. You may exceed any reasonable size of the command line ... Look in to `WM_COPYDATA` -- [here](http://stackoverflow.com/questions/2451103/use-wm-copydata-to-send-data-between-processes) is an example on SO. – Jongware May 03 '15 at 14:19
  • Well, command line takes stringized parameters (`int main(int argc,char* argv[])`), where `argc` tells you how many are there. That's not a very good format to represent a 2D array. But possible though of course: You pass the first 2 parameters to specify the dimensions of your array, and all the following parameters are the particular values. Could you elaborate, why _file is not an option_ please? – πάντα ῥεῖ May 03 '15 at 14:20
  • @πάνταῥεῖ: Maybe I was not entirely clear, what I want. The vbscript array is filled up with data, and I like to call the exe only once, passing the whole array, and then process it inside the exe. I don't want to pass the items one by one to the exe. I want to pass the whole array somehow. – kampi May 03 '15 at 14:24
  • 1
    @kampi I well understood what you want to do. _" I want to pass the whole array somehow. "_ Then you probably should lookup for shared memory or pipe. Command line won't support what you want, as well an intermediate file would do so. I didn't tell anything about you should call your `.exe` more than once. – πάντα ῥεῖ May 03 '15 at 14:28
  • @πάνταῥεῖ: Sorry, I misunderstood you then. I thought, you suggest to call the exe for every item of the array, and pass the items that way. – kampi May 03 '15 at 14:41
  • Re "Creating any file on the hard drive is not an option unfortunately.", that sounds silly to me. As you run the program a lot of temporary files are created by Windows. One more temporary file, your own, does not matter. – Cheers and hth. - Alf May 03 '15 at 14:51

1 Answers1

0

It could help to know

  • what your arrays contain (text? numbers?), and

  • the host environment for your script (browser? Windows Script Host? HTA? widget? what?), and

  • whether you control the C++ code.

It's not so good an idea to ask a technical question and leave out the most relevant technical details.

Anyway, here are some options:

  • Design a command line syntax for representing the data textually. Convert, invoke exe with that command line. Note that command lines are limited to about 32 KB, and the command interpreter imposes a limit of 8 KB.

  • Define a C++ Automation object. On the C++ receiving end you'd probably use OLE SafeArray. Instantiate and call such an object from VBScript.

  • Or you can turn that around and implement an Automation object in VBScript, packaged in WSH files, and invoke that from C++.

  • Store the data in a file, pass the filename to C++ exe. In WSH you have easy access to text files, not so sure about browser host. For text file, non-textual data involves conversion to text, again.

  • Use Windows piping or Windows mailslots to pass the data at run time.

Probably more ways also, depending on what you're doing. ;-)

Community
  • 1
  • 1
Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
  • I updated my question. Sorry, I didn`t thought that it could be important what the array contains. – kampi May 03 '15 at 14:44