Control by External Programs

ImageLab can be controlled by external programs by sending a Windows WM_CopyData message to ImageLab which contains either a filename of a data file (.ILAB file) or the name of an ImageLab script (file extension '.ISCR'). If the message does not contain a valid filename ImageLab either generates an appropriate error dialog or ignores the message (the actual behavior depends on the state of the switch "Provide a Status Message on Faulty External Control").

The filename may either be passed as a fully specified path (disk character, path, and filename) or with no path at all (filename only). If ImageLab receives a filename without a path it is assumed that the file to be loaded is located in the current working directory.

If the file extension of the passed filename is '.ILAB' the corresponding data file is loaded. Please note that a complete ImageLab dataset consists of several files (.ilab and .cube as a minimum).

In order to control ImageLab by an external program, this program first has to create a suitable ImageLab script and then pass the filename of the script to ImageLab.

Hint: Please note that full external control via ILabPascal scripts is only possible if you are using the Extended Version of ImageLab.


When sending the message to ImageLab, one of the following error codes is returned:

Error Code Explanation
0 everything OK, data loaded or script executed successfully
-1 the script or file specified by the script does not exist
-2 script is too old (minimum required version is higher than installed ImageLab version)
-3 script execution error
-4 script compilation failed
-5 script aborted by user

Example: The following Delphi routine shows an example how to control ImageLab by an external program:
function TForm1.SendMsgToImageLab (DLMsg: AnsiString): integer;

  copyDataStruct : TCopyDataStruct;
  receiverHandle : THandle;

copyDataStruct.dwData := 0;
copyDataStruct.cbData := 1 + Length(DLMsg);
copyDataStruct.lpData := PAnsiChar(DLMsg);
receiverHandle := FindWindow(PChar('TFrmImageLab'), nil);
if receiverHandle = 0
  then result := -9999
  else result := SendMessage (receiverHandle, WM_COPYDATA,
                              Integer(Application.Handle), Integer(@copyDataStruct)) ;

Last Update: 2017-Jun-14