473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

H,

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 );
  2.  
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;
  6.  
  7. typedef struct CountDevices_s
  8. {
  9.     BYTE p_devicesSize;
  10.     pDevices_t p_device;
  11. }CountDevices_t;
  12.  
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
Nov 1 '10 #1
1 2002
weaknessforcats
9,208 Expert Mod 8TB
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

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

Similar topics

18
by: deko | last post by:
I have a counter file that records page hits - each hit is a UNIX timestamp in the file. But I'm only interested in page hits in the last 365 days. The below code creates an array from the file...
2
by: Fain Cowie | last post by:
I am trying to paste a pile of text boxes onto a large form in groups of 15 when I try to copy the first group (0-14)and paste it below the elements are numbered backwards.(29-15) Is there a way to...
3
by: some one | last post by:
Which of the following definition is more efficient? struct TestData { int a; int b; int var1; int var2; int var3; int var4; int var5; int var6;
6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
8
by: ljlevend2 | last post by:
If a property's type is an array and the property is exposed in a PropertyGrid, then the property can be expanded so that the user can view and edit the array elements. But, I've noticed that if...
6
by: Kumar | last post by:
How should I declare the array elements being half word? and the array elements of the type byte in C?? Please help Kumar
8
by: SP | last post by:
The following code crashes after I add the two nested FOR loops at the end, I am starting to learn about pointers and would like to understand what I'm doing wrong. I think the problem is the way...
14
by: dan | last post by:
I would like to have the preprocessor automatically generate the number of array elements requested. Each element is zero. The elements get pasted into a larger array. The other elements may be...
12
by: estantep | last post by:
Hello, I am having some trouble trying to pass a pointer to an structure array (as function argument), when executing I get seg faults. The best I could get out from googling was: #define...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.