Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AfxBeginThread passed pointer information lost

Status
Not open for further replies.

Technokrat

Programmer
Jul 20, 2001
92
US
hello,

I'm trying to use a thread to retrieve inventory level information from a db, and store it in a map. Below I have included the struct from the header file, and the call to the thread. I am initializing the structure with an inventory item id, and date range prior to the thread call. However, once inside the thread the information pointed to in the structure is no longer available. Can anybody see what I'm doing wrong, or does anybody have a different recommended approach?

Code:
// header file
typedef struct _InvDetail
{	
	CString csInvID;
	CString csFromDt;
	CString csToDt;
	float	fPurchased;
	float	fXfer;
	float	fBeginInv;
} InvDetail, *PtrInvDetail;

// code snippet ----------------------------
PtrInvDetail pInvDetail = new InvDetail;

	pInvDetail->csInvID = csInvID;
	pInvDetail->csFromDt = dtBusDate.Format();
	pInvDetail->csToDt = csUpdDate;
	
	m_mapInvDetail.SetAt(csInvID, pInvDetail);
	
	AfxBeginThread(ThreadInvDetail, (LPVOID)&pInvDetail);
}

UINT ThreadInvDetail(LPVOID pParam)
{
	InvDetail* pInvDetail = (InvDetail*)pParam;

// end of snippet

pInvDetail->csInvID no longer contains the inventory id, why?

Thank you in advance for the feedback.

 
You should be passing pInvDetail: not &pInvDetail.
Code:
    AfxBeginThread(ThreadInvDetail, (LPVOID)pInvDetail);
}

UINT ThreadInvDetail(LPVOID pParam)
{
    // This wants a InvDetail* not a InvDetail**
    InvDetail* pInvDetail = (InvDetail*)pParam;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top