UFFI counterpart to "C iterate over a arry through a pointer"

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

UFFI counterpart to "C iterate over a arry through a pointer"

ASAM
Hello, I'm looking for help with the following problem.
I try to get closer from the C point of view to the problem.

//These are the structures
typedef struct {
  unsigned int  NumEntries;      /* number of entries written to the
pModuleData array */
  MODULE_DATA *pModuleData;      /* pointer to array containing module infos
and module handles */
} MODULE;

typedef struct {
   unsigned int ModuleTypeId;    /* ModuleTypeId */
   unsigned int hMod;            /* handle Module assigned */
   char   *pVendorModuleName;    /* Vendor specific information string. */
} MODULE_DATA;

//this is a function that I call via FFI
unsigned int errorCheck GetModuleIds(MODULE  **pModuleIdList)
{
        //memory will be allocated here and the structure will be filled.
}

Now my questions :-)


I solve the pointer pointer problem with ExternalAddress and MODULE
fromHandle:

| result pointerAutoRelease mod|
        pointerAutoRelease := ExternalAddress new pointerAutoRelease.
        result := call ffiGetModuleIds: pointerAutoRelease.
        "inside Methode -> ffiGetModuleIds ^self ffiCall:#(uint32
GetModuleIds( void** pModuleIdList ) )"
        "result is unimportant for understanding the problem"
        mod := MODULE fromHandle: pointerAutoRelease.
       
Is this a good way? Or is there a better solution?


And now comes my main problem...
How do I get my array( or Collection) from NumEntries and *pModuleData with
ffi?

So I would do it roughly in C.
main(){
   
    MODULE_DATA *pModuleData;
        MODULE *moduleIdList=NULL;
        unsigned int retval = GetModuleIds(&moduleIdList);

        printf("Number of modules: %d\n\n",moduleIdList->NumEntries);
 
        for (unsigned int i=0;i<moduleIdList->NumEntries;i++)
        {
                // Set a pointer to the current ModuleData
        pModuleData = &moduleIdList->pModuleData[i];  //is like iterate
through a pointer
               
                //etc. .....
                ...
        }
       
}

Thanks you for your help.



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html