I'm using Win32 API and the _beginthreadex call to run a thread the following way:
struct StructItem
{
std::string title;
int amount;
};
StructItem structItems[33];
unsigned int id;
HANDLE thread = (HANDLE)_beginthreadex(NULL, 0, my_thread, (void*)structItems, 0, &id);
And this is my thread:
unsigned int __stdcall my_thread(void *p)
{
for (int i = 0; i < 20; i++)
{
// todo: print struct.title
Sleep(1000);
}
return 0;
}
As far as I understood the *p is a pointer to my list of structures, since I passed them to the 4th argument in the _beginthreadex call, but I can't understand how can I cast the *p so that I can access the array of structs from within the thread?