Contents Previous Next Subchapters

Outputting Data From an OMDDE Server
Source Files: winmain.c omdde.c dderror.c omdde.h

Prototype
void OMServerOutput(
     enum type_mat  *
mtype,
     int            *
nr
     int            *
nc,
     void           *
data
)


Description
This function is called when an OMDDE client requests a matrix from the server. (The client makes this request by calling OMClientGetMat .) The input values of mtype, nr, and nc do not matter. The output value of mtype specifies the type of the matrix and is one of the types in the O-Matrix Types table. The value of mtype may also be UNDEF_mat in which case the server does not yet have a matrix to send to the client. The output value of nr specifies the number of rows in the matrix. The output value of nc specifies the number of columns in the matrix. If the input value of data is equal to NULL, the elements of the matrix are not returned. This call is be used by the client to find out the size of the matrix. If the input value of data is not equal to NULL, it points to OMSize(mtype) times nr times nc bytes of memory where mtype, n, and nc correspond to the previous call to OMServerOutput. In this case, the elements of the matrix are be placed in the memory pointed to by data. This elements will be in column major order; i.e., the first column followed by the second etc.

Example
When linked with the program WinMain , the example below sends a sequence of row vectors of increasing length to the client. Note that the matrix is not actually counted as transferred unless data is equal to NULL.

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

extern void AddText(char *add);

static int Count = 1;

int OMServerCmd(char *cmd)
{    AddText("OMServerCmd: Execution is requested for the command\n");
     AddText(cmd);
     return TRUE;
}
int OMServerInput(enum type_mat mtype, int nr, int nc, void *data)
{    return FALSE;
}
void OMServerOutput(enum type_mat *mtype, int *nr, int *nc, void *data)
{    int  i;
     mint *ptr;

     *mtype     = INT_mat;
     *nr        = 1;
     *nc        = Count;

     if( data == NULL )
     {    AddText("OMServerOutput: data == NULL\n");
          return;
     }
     AddText("OMServerOutput: data != NULL\n");

     ptr = (mint *) data;
     for(i = 0; i < Count; i++)
          ptr[i] =  i + 1;

     Count++;
     return;
}

void Setup()
{    
     int    ok;

     AddText("Demo OMServerOutput\n");
     ok = OMDdeInitialize();
     if( ! ok )
     {    AddText("Cannot initialize OMDDE\n");
          return;
     }
     ok = OMServerRegister("C-Server");
     if( ! ok )
     {    AddText("Cannot register server\n");
          OMDdeUninitialize();
          return;
     }
}

void ShutDown()
{
     OMDdeUninitialize();
     return;
}

If you have the Microsoft Visual C++ compiler, you can compile and link this example by executing the command
     nmake /f windows.mak omserout.exe
in the directory c:\omwin\omdde. If you then execute the command
     omserout
then run a copy of O-Matrix, and at the O> prompt you enter
     omlink("client", "C-server")
O-Matrix will respond
     T
If you continue by entering
     omlink("get")
O-Matrix will respond
     1
and the server will respond
     OMServerOutput: data == NULL
     OMServerOutput: data != NULL
If you continue by entering
     omlink("get")
O-Matrix will respond
     [ 1 , 2 ]
and the server will respond
     OMServerOutput: data == NULL
     OMServerOutput: data != NULL