By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,871 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

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

P: 3

I need to call an API with the follwoing prototype:

Expand|Select|Wrap|Line Numbers
  1. 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?
Expand|Select|Wrap|Line Numbers
  1. typedef struct pDevices_s
  2. {
  3.     char deviceName[256];
  4.     char deviceKey[16];
  5. }pDevices_t;
  7. typedef struct CountDevices_s
  8. {
  9.     BYTE p_devicesSize;
  10.     pDevices_t p_device;
  11. }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.
Nov 1 '10 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,197
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.
Nov 1 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.