The underlying design of the C API is object based, and a hierarchy of objects can be established. The hierarchy reflects specialization of object types, an example is the Message object which is a specialization of the Fields object (seeFundamental objects).
As an example, assume that we have an MQeVehicle object and an MQeCar object. MQeCar is a specialization of MQeVehicle. Both of these objects could have the function move() defined on them, but MQeCar also has a fillPetrol() function. Both objects must also have new() and free() functions to create new objects and to return the handles.
Assume the following (using standard WebSphere MQ Everyplace API conventions):
mqeVehicle_new(MQeExceptBlock *pErrStruct, MQeVehicleHndl *phNewVehicleHndl); mqeVehicle_free(MQeVehicleHndl hVehicleHndl, MQeExceptBlock *pErrStruct); mqeVehicle_move(MQeVehichleHndl hVehicleHndl, MQeExceptBlock *pErrStruct); mqeCar_new(MQeExceptBlock *pErrStruct, MQeCarHndl *phNewCarHndl); mqeCar_free(MQeCarHndl hCarHndl, MQeExceptBlock *pErrStruct); mqeCar_fillPetrol(MQeCarHndl hCarHndl, MQeExceptBlock *pErrStruct);
New objects can be created like this:
MQeVehicleHndl hMyVehicle; MQeCarHndl hMyCar; rc = mqeVehicle_new(&exceptBlock, &hMyVehicle); rc = mqeCar_new(&exceptBlock, &MyCar);
Using the handle to the MQeCar object you can fill the car with petrol:
rc = mqeCar_fillPetrol(hMyCar, &exceptBlock);
Note that the following call would fail, with a Return Code 10400 - MQERETURN_INVLAID_ARGUMENT, because MQeVehicle is not specialization of MQeCar.
rc = mqeCar_fillPetrol(hMyVehicle, &Block)
Both of the following calls are valid, because MQeCar is a specialization of MQeVehicle:
rc = mqeVehicle_move(hMyCar, &exceptBlock); rc = mqeVehicle_move(hMyVehicle, &exceptBlock);
Such functions are known as polymorphic. Potentially different implements are called depending on the nature of handle you pass in.
To free the storage you should call the following functions
rc = mqeCar_free(hMyCar, &exceptBlock); rc = mqeVehcile_free(hMyVehicle, &exceptBlock);