|
MXSetValue |
C
NetProg Library |
|
#include
"mx.h"
|
|
|
int MXSetValue (MXMessage* pmessage, char* name, int range, void* value) |
|
Parameters |
Description |
pmessage |
the
message instance |
name |
the
name of the object |
range |
the
range of the object |
value |
the
value to set |
This function set values to
objects in the message pmessage. The name and the range parmeters
represent the name and the range of the object .
The value specifies a
pointer to the value to set
To understand we suppose a
dialog class defined in the resource file as follow :
DIALOGCLASS 1 *mydialog*
BEGIN
MESSAGECLASS Ask (STRING session[2] STRING passwd1)
MESSAGECLASS reply (STRING session[2] SHORT ret)
END
MXLoadResourceFile (pmx,
"ResourceFileName");
- Open a connection with
another application
pcom = MXOpenTCP
(pmx, "MachineName", port, ...);
- In the application program
you create and put a message in the output queue of the connection pcom
as follow :
pmessage = MXPutMesage
(pcom, "mydialog", "Ask");
- At this point pmessage is
not sent, you affect values to this message as follow :
MXSetValue (pmessage,
"Session", 1, "String1");
MXSetValue (pmessage, "Session", 2, "String2");
MXSetValue (pmessage, "Ask", "Myname");
- Or another method to set
values to pmessage is in the callback that the application adds to the
pmessage message class :
MXAddComCallBack (pmx, pcom,
"mydialog", "Ask", MXONSEND, Myfunction, NULL);
int MyFunction (MXMessage*
pmessage, MXCom* pcom, void* appfield)
{
MXSetValue (pmessage, "Session", 1, "String1");
MXSetValue (pmessage, "Session", 2, "String2");
MXSetValue (pmessage, "Ask", "Myname");
return 1;
}
Values will be set in the
callback just before sending the message.
- The pmessage is sent either
by MXDispatchEvents in an Asynchronous way or explicitly with the function
MXSend in a Synchronous way :
MXSend
(pmx, pcom , pmessage);
MXFreeMessage
(pmx, pmessage);
With
MXSend the message instance should be freed
Return
Values : returns -1 if error else returns > 0
|
...
int AckStatement (MXMessage* pmessage, MXCom* pcom, void* par)
{
LONG RowsProcessed = (LONG) MXGetValue (pmessage, "RowsProcessed", 1);
LONG SqlCode = (LONG) MXGetValue (pmessage, "SqlCode", 1);
STRING SqlErrMsg = (STRING)MXGetValue (pmessage, "SqlErrMsg", 1);
printf ("Ack Result = %s , %d, %d\n", SqlErrMsg , RowsProcessed, SqlCode);
return 1 ;
}
...
int main(int argc, char *args[])
{
MX mx;
MXMessage* pmessage;
MXCom* DBCom1;
BYTE TreatmentType = OSSEQUENTIALTREATMENT;
BYTE StorageType = 1;
DWORD Every = 2;
DWORD MaxRows = 30;
MXInit (&mx, MXSERVER, NULL, NULL, 0, NULL);
DBCom1 = MXOpenBase (&mx, "Douane_W2K-TST",
"Douane", "Douane", DBPROTO_ODBC, TRUE);
if (!DBCom1) return 0;
MXAddComCallBack (&mx, DBCom1,
DB_SYS, "ReceiveHeader", MXONRECV, ReceiveQueryHeader, NULL);
MXAddComCallBack (&mx, DBCom1, DB_SYS, "ResultSet", MXONRECV, ReceiveQueryBuffer, NULL);
MXAddComCallBack (&mx, DBCom1, DB_SYS, "AckStatement", MXONRECV, AckStatement, NULL);
pmessage = MXPutMessage (DBCom1, DB_SYS,
"ExecuteQuery");
MXSetValue (pmessage, "SqlStatement", 1, "SELECT * FROM colis");
MXSetValue (pmessage, "TreatmentType", 1, &TreatmentType);
MXSetValue (pmessage, "StorageType", 1, &StorageType);
MXSetValue (pmessage, "Every", 1, &Every);
MXSetValue (pmessage, "MaxRows", 1, &MaxRows);
...
MXDispatchEvents (&mx, 0);
MXEnd (&mx);
return 0;
}
|
|