#include <hmq.h> MQEINT32 MQeFieldsPutByStruct( MQEHSESS hSess, MQEHFIELDS hFlds, MQEVOID * pStruct, struct MQeFieldStructDescriptor pfsd[], MQEINT32 nSds, MQEINT32 * pCompCode, MQEINT32 * pReason)
#include <hmq.h> static MQECHAR const * FieldsType = "com.ibm.mqe.MQeFields"; struct myData_st { MQEINT32 x; /* simple variable */ MQECHAR *name ; /* pointer to name buffer */ MQEINT32 namelen; /* length of name */ MQEBYTE buf[8]; /* fixed buffer in struct */ MQEINT32 fieldlen; /* length of a field, buffer not in struct */ }; MQEINT32 field[10]; /* buffer whose length is in a structure */ /* A possible sample definition of MQEFIELDDESC for myData_st */ static MQEFIELDDESC myDataStruct_fd[] = { {"x", 1, MQE_TYPE_INT, 0, 0, 1}, {"name", 4, MQE_TYPE_ASCII, MQSTRUCT_LEN|MQSTRUCT_DATA, 4, 64}, {"buf", 3, MQE_TYPE_BYTE, 0, 12, 8}, {"field",5, MQE_TYPE_INT, MQSTRUCT_LEN|MQSTRUCT_NODATA, 20, 0} }; static MQECHAR * textVal = "The Owl and the Pussy Cat went to sea."; static MQECHAR textBuf[] = { 0xAB, 0xCD, 0x12, 0x44}; MQEHSESS hSess; MQEINT32 compcode; MQEINT32 reason; MQEHFIELDS hFlds; struct myData_st myData; MQEINT32 int32Val; MQEINT32 rc; /* Initialize data */ myData.x = 20; myData.name = textVal; myData.namelen = strlen(textVal); myData.fieldlen = 10; for (rc=0; rc<4; rc++) myData.buf[rc] = textVal[rc]; for (rc=0; rc<sizeof(myData.buf); rc++) myData.buf[rc] = 0; for (rc=0; rc<myData.fieldlen; rc++) field[rc] = rc; hSess = MQeInitialize("MyAppsName", &compcode, &reason); hFlds = MQeFieldsAlloc( hSess, FieldsType, &compcode, &reason); /* Put the data structure into the fields object. */ rc = MQeFieldsPutByStruct( hSess, hFlds, &myData , myDataStruct_fd, 4, &compcode, &reason); /* Add "field" whose length is in myData.fieldlen */ rc = MQeFieldsPut( hSess, hFlds, "field", MQE_TYPE_INT, &field, myData.fieldlen, &compcode, &reason);