Help required for API's returning data to structured arrays.

Windows specific forum
Lucifer
User
User
Posts: 26
Joined: Wed Apr 30, 2003 6:11 pm
Location: UK

Help required for API's returning data to structured arrays.

Post by Lucifer »

I’m starting to get into some slightly advanced programming that requires the use of Windows and third party API’s on Windows 8.1 with PB 5.21 LTS. I use many of the simple Windows API’s and I’m happy with the basic use of structures and linked lists but some of the API’s want to return data to a structured array.

I create my structure, create a list of type my structure, I give the API the pointer of the list but that’s when I get problems?
I assume I need to somehow determine the size of my list to be and then allocate that memory. How do I do that? I know how to allocate memory but I may be missing the point of how the allocated memory, structured list and API all fit together.

To give an idea of the things I’m attempting, I’ve been trying to work with IP controlled power sockets and the API wants to return a list of found devices to a structured array.
NFC reader/writer API wants to do a similar devices found task.
Finally I want to control the source input of my monitors using the dxva2.dll. With multiple monitors, again a structured array of a list of found devices.

I do apologise in advance if it is here as I may be using the wrong search criteria. I have tried searching the forum, the web and the manual for help but I can’t seem to find anything on this specific issue within PB.

Any help, advice, links or samples would be welcome. I’m not looking for a “please do it for me”, I want to learn and understand how it’s done and I learn better when following an example. I’m sure it’s something stupid I’m not doing or understanding.

Many thanks.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Help required for API's returning data to structured arr

Post by Danilo »

Allocate an structured Array:
Dim arr.StructType( count ) ; arr() is the address of the whole array, or @arr(0)

Allocate structured memory:
*mem.StructType = AllocateMemory( count * Sizeof(StructType) ) ; *mem is the address of the whole structured memory block
Lucifer
User
User
Posts: 26
Joined: Wed Apr 30, 2003 6:11 pm
Location: UK

Re: Help required for API's returning data to structured arr

Post by Lucifer »

Many thanks for that Danilo.
Post Reply