How to implement a byte * to point to structure of array elements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eran yurman
    New Member
    • Nov 2010
    • 3

    How to implement a byte * to point to structure of array elements

    H,

    I need to call an API with the follwoing prototype:

    Code:
    unsigned long CountDevices (BYTE *p_deviceSize,BYTE *p_device );
    I have no knowledge of the content of the API function itself but it is unimportant. The API should receive values from the network into p_deviceSize and p_device.

    p_deviceSize is used as input/output. Upon input it gets the max elements of device array. Upon output, the actual size of the device array.
    p_device is a structure of array elements
    as follows:
    deviceName which is a char[256] element used as an output
    deviceKey which is a char[16] element used as an output

    and to my question:
    1st, the API is currently not applicable because there is no network to return values so what i want to do is write a stub function that will simulate the returning of values into the API's parameters.

    How is the correct way to create the CountDevices_t structure? is it correct to create the structures like the below?
    Code:
    typedef struct pDevices_s
    {
    	char deviceName[256];
    	char deviceKey[16];
    }pDevices_t;
    
    typedef struct CountDevices_s
    {
        BYTE p_devicesSize;
        pDevices_t p_device;
    }CountDevices_t;
    In this case it is easy to write a stub that will simulate values to each member of the structures, however this is not what the API intended.
    How is the correct way to create the CountDevices_t structure?
    How to implement a stub function to fill that structure where BYTE * actually points to a structure of array? casting a pDevices_t to and array member of p_device?

    Hope the question is clear.
    Thanks in advance.
    Eran
    Last edited by Banfa; Nov 1 '10, 10:54 AM. Reason: Corrected the code tags
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What am I missing?

    The function retuns and unsigned long, so hard code a return value.

    Ditto for the arrays using BYTE*.

    As far as I can see you don't need a struct in your stub.

    Comment

    Working...