i have a bunch of data i want to pass to CreateThread. i created a struct as per the msdn documentation. here it is:

typedef struct ThreadRecvData
{
	std::list<char> data;
	Ogre::String addr;
	unsigned long port;
} THREADRECVDATA, *PTHREADRECVDATA;

then i initialise the struct, again as per the msdn documentation:

PTHREADRECVDATA pThreadRecvData;
pThreadRecvData = (PTHREADRECVDATA) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(THREADRECVDATA));
pThreadRecvData->addr = "123";
pThreadRecvData->port = 123;
pThreadRecvData->data.push_back('x');

i get a crash at pThreadRecvData->data.push_back('x').

can anyone help ?

thank you.

Recommended Answers

All 2 Replies

You probably can't use HeapAlloc() to allocate memory for pThreadRecvData because std::list allocated memory from the standard heap using new operator. Replace HeapAlloc() with new and retest.

You probably can't use HeapAlloc() to allocate memory for pThreadRecvData because std::list allocated memory from the standard heap using new operator. Replace HeapAlloc() with new and retest.

i used new and yes it does indeed work. i wanted really to understand what was happening - so thanks for the explanation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.