NetProg

 


   

NETPROG  PRESENTATION

 

  OverView
  Functionalities
  Programming
API
C Examples
  Download
MXAddApplicationProcedure C NetProg Library 


#include "mx.h"
int MXAddApplicationProcedure (MX* pmx, int (*funct)(MX* pmx, void* applicationfield), void* applicationfield)


Parameters Description
pmx  the MX manager
funct  the function to call by the manager
applicationfield  Programmer-specified data sent to the callback function


Description : 

This function is used when an application wants to do some background work, by the MX manager. Usually the function MXDispatchEvents which manages all events does not return if its time parameter is set to 0. In this case, if the application wants to do some processing, it should add a callback that will be called automatically by the MX manager in a scheduled manner as long as the callback returns a value different from 0. If the callback returns the value 0, and if the MX manager has no other events to treat, this function will not be called and  no more cpu is consumed.The next call to this callback will occur after an external event wakes up the MX manager.


Return Values : returns -1 if error else returns 0


See Also : MXRemoveApplicationProcedure, MXDispatchEvents 


Example :

 

int PromptUser (MX* pmx, void* appfield)
{

  MXCom* pcom = (MXCom*)appfield;
  MXMessage* pmessage;
  char Buffer[500];


  putchar ('S');putchar ('C');putchar ('>');
  gets (Buffer);

/* do whatever you want */

 

  MXPutMessage (pcom, "DialogName", "MessageClassName");

  MXSetValue (pmessage, ....
  ...
  if (ContinueToPrompt)

    return 1;

  else

    return 0;

}

 

 int main(int argc, char* argv[])
{
  MX mx;
  MXCom* pcom;

/* You define your dialog class in the file MyResourceFile.irc */


  MXInit (&mx, MXSERVER, NULL, NULL, 0, "MyResourceFile.irc");
  pcom = MXOpenTCP (pmx, "MachineName", 3005, IPPROTO_DG, NULL, NULL, TRUE);
  if (!pcom) return -1;

  MXAddAddApplicationProcedure (&mx, PromptUser, pcom);

  MXDispatchEvents (&mx, 0);

  MXEnd (&mx);
}