How to dynamically fill the structure which is a pointer to pointer of arrays in C++ implementing xfs -


structure 1:

typedef struct _wfs_cdm_cu_info {     ushort ustellerid;     ushort uscount;     lpwfscdmcashunit * lpplist; } wfscdmcuinfo, * lpwfscdmcuinfo;  

structure 2:

typedef struct _wfs_cdm_cashunit {     ushort usnumber;     ushort ustype;     lpstr lpszcashunitname;     char cunitid[5];     char ccurrencyid[3];     ulong ulvalues;     ulong ulinitialcount;     ulong ulcount;     ulong ulrejectcount;     ulong ulminimum;     ulong ulmaximum;     bool bapplock;     ushort usstatus;     ushort usnumphysicalcus;     lpwfscdmphcu * lppphysical; } wfscdmcashunit, * lpwfscdmcashunit; 

structure 3:

typedef struct _wfs_cdm_physicalcu {     lpstr lpphysicalpositionname;     char cunitid[5];     ulong ulinitialcount;     ulong ulcount;     ulong ulrejectcount;     ulong ulmaximum;     ushort uspstatus;     bool bhardwaresensor; } wfscdmphcu, * lpwfscdmphcu;       

the code:

 lpwfscdmcuinfo lpwfscdmcuinf = null;    lpwfscdmcashunit lpwfscdmcashunit =  null;    lpwfscdmphcu   lpwfscdmphcu = null;    int i=0; try  {     hresult = wfmallocatebuffer(sizeof(wfscdmcuinfo),wfs_mem_zeroinit|wfs_mem_share,(void**)&lpwfscdmcuinf);      lpwfscdmcuinf->uscount =7;        lpwfscdmcuinf->ustellerid = 0;               hresult = wfmallocatemore(7*sizeof(lpwfscdmcashunit),lpwfscdmcuinf,(void**)&lpwfscdmcuinf->lpplist);        for(i=0;i<7;i++)     {         lpwfscdmcashunit   lpwfscdmcashunit = null;           hresult = wfmallocatemore(sizeof(wfscdmcashunit), lpwfscdmcuinf, (void**)&lpwfscdmcashunit);         lpwfscdmcuinf->lpplist[i] = lpwfscdmcashunit;//store pointer         //filling cash unit         -----------------------------          lpwfscdmcashunit->ulvalues =50;         -----------------------------         wfmallocatemore(1* sizeof(lpwfscdmphcu), lpwfscdmcuinf, (void**)&lpwfscdmcashunit->lppphysical);// allocate physical unit structure         for(int j=0;j<1;j++)         {             lpwfscdmphcu   lpwfscdmphcu = null;               hresult = wfmallocatemore(sizeof(wfscdmphcu), lpwfscdmcuinf, (void**)&lpwfscdmphcu);             lpwfscdmcashunit->lppphysical[j] = lpwfscdmphcu;              //filling phy cashunit             -------------------------------------------------------             lpwfscdmphcu->ulmaximum = 2000;               -----------------------------         }      }      //lpwfscdmcuinf->lpplist=&lpwfscdmcashunit;     hresult =wfsexecute (hservice,wfs_cmd_cdm_end_exchange,(lpvoid)&lpwfscdmcuinf,60000,&lppresult);     return (int)hresult; 

i'm getting stuck while retrieve values in structure 1. need dynamically add values these structure , display structure1 output.an allocation of memory needs done this.i have tried using above code allocating memory in spite of allocating values not stored in structure.

the value of uscount changes per denomination set. based on usnumphysicalcus set. when send &lpwfscdmcuinf within wfsexecutemethod lppphysical seems empty.

i cant figure out i'm getting wrong.

first of must allocate memory each block. pointers array allocate memory store count of pointers, each pointer in allocated memory must allocate memory structure itself. rewrite code in more short form. there no error checking , code sample only.

lpwfscdmcuinfo lpwfscdmcuinf = null; hresult hr = wfmallocatebuffer(sizeof(wfscdmcuinfo), wfs_mem_zeroinit|wfs_mem_share, (void**)&lpwfscdmcuinf); // allocate 7 times of wfscdmcashunit const int cucount = 7; lpwfscdmcuinf->uscount = cucount; hr = wfmallocatemore(cucount * sizeof(lpwfscdmcashunit), lpwfscdmcuinf, (void**)&lpwfscdmcuinf->lpplist); (int i=0; < cucount; i++)  {     // 1 entry     lpwfscdmcashunit currentcu = null;     hr = wfmallocatemore(sizeof(wfscdmcashunit), lpwfscdmcuinf, (void**)&currentcu);     // store pinter     lpwfscdmcuinf->lpplist[i] = currentcu;     // fill current cu data here     // ....      // allocate phisical unit pointers     const int phucount = 1;     currentcu->usnumphysicalcus = phucount;     wfmallocatemore(phucount * sizeof(lpwfscdmphcu), lpwfscdmcuinf, (void**)&currentcu->lppphysical);     // allocate phisical unit structure     (int j=0; j < phucount; j++)     {         lpwfscdmphcu phucurrent = null;         // allocate phisical unit structure         wfmallocatemore(sizeof(wfscdmphcu), lpwfscdmcuinf, (void**)&phucurrent);         currentcu->lppphysical[j] = phucurrent;         // fill phisical unit here         // ..         // ..     } } 

in additional sample recommend write helper function allocate xfs structures wfscdmcuinfo. in own project i've used macro serialize xfs structure in memory wfmallocate , wfmallocatemore functions. xfs structures complex , different class class. wrote macros serialize , deserialize structures in memory stream , xfs memory buffers. in application use heap alloc store xfs structures in memory, when need return structures in xfs message need transfer memory buffers xfs memory wfmallocate , wfmallocatemore.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -