Contents Previous Next Subchapters

Transferring Commands From OMDDE Client to Server

Prototype
char *OMClientPutCmd(int id, char *cmd)

Description
This function call transfers commands from a client to a server for execution by the server. The argument id is an integer index returned by a previous call to OMClientConnect . It specifies the server that the commands are being sent to. The argument cmd is a '\0' terminated character string containing the commands that are being sent to the server. If the return value is equal to "ok", the commands were accepted by the server for execution. If the return value is equal to "busy", the server is currently busy and will not accept the commands. Any other return value is an error message.

Example
The following example prints
     Hello World
in the command window of a currently running copy of O-Matrix. It is in the file omclicmd.c in the directory omwin\omdde. If you have the Microsoft Visual C++ compiler, it can be compiled and linked by executing the command
     nmake /f console.mak omclicmd.exe
in that directory.

# include <stdio.h>
# include "define\omdde.h"
# include "define\noserver.h"

int main()
{    
     int    id;
     int    ok;

     char   *msg;
     char   *cmd = "print \"Hello World\"";

     ok = OMDdeInitialize();
     if( ! ok )
     {    printf("Cannot initialize OMDDE\n");
          return 1;
     }

     id = OMClientConnect("O-Matrix");
     if( id == OMDDE_CONNECTION_FAILED ) 
     {    printf("Cannot connect to O-Matrix\n");
          return 1;
     }

     msg = OMClientPutCmd(id, cmd);
     if( strcmp(msg, "ok") != 0 )
     {    printf("Command transfer failed: %s\n", msg);
          return 1;
     }

     OMDdeUninitialize();
     return 0;
}

Reference
Invalid memory will be accessed if id is not equal to a previous return value of OMClientConnect.