HGetCParNum returns the length of input control arrays of the input control parameter with the index par (1… n). This makes it possible to allocate exactly as much memory for parameter values as needed for reading them, for example, via HCopyElemL, HCopyElemD, or HGetCPar. As an alternative, you can use the reference passing routines as HGetPElem or HGetPPar, or routines as HGetElemL that allocate memory implicitly. Figure 5.34 shows an application of HGetCParNum.
Note that HGetCParNum automatically checks the result state of the underlying procedure similarly to the macro HCkP (see section “HCkP”). Thus, you must not use HCkP on HGetCParNum yourself.
Hcpar par1,par2; Hcpar *par3; INT4_8 num; /* allocate memory for strings */ HAllocStringMem(proc_handle,1000); /* read a short/int/long value in parameter 1 */ HGetSPar(proc_handle,1,LONG_PAR,&par1,1); /* now par1.par.l == 5 */ /* read a string in parameter 2 */ HGetSPar(proc_handle,2,STRING_PAR,&par2,1); /* now par2.par.s == "Text" */ /* read a tuple of float values in parameter 3; */ /* first, get the number of values */ HGetCParNum(proc_handle,3,&num); /* now num == 3 */ /* second, allocate memory for the values and read them */ HCkP(HAllocTmp(proc_handle,(void**)&par3,(size_t)(num*sizeof(Hcpar)))); HGetSPar(proc_handle,3,DOUBLE_PAR,par3,num); for (i=0; i<num; i++) { /* par3[i].par.d == 0.5,1.7,4.4 */ ...
Figure 5.34: Use HGetCParNum to get the number of control values before reading the control parameter values of the operator call demo(5,'Text',[0.5,1.7,4.4]).