Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC
I have made one view file with one Thrad procedure function ThreadProc. While compiling it gives error as:
 
ThreadDemoView.cpp(114) : error C2146: syntax error : missing ; before identifier 'ThreadProc';
ThreadDemoView.cpp(114) : error C2501: UNIT; : missing storage-class or type specifiers
fatal error C1004: unexpected end of file found
Error executing cl.exe.
 
I am new in mfc please help.
 

 

 

 

// ThreadDemoView.cpp : implementation of the CThreadDemoView class
//

#include "stdafx.h"
#include "ThreadDemo.h"
 
#include "ThreadDemoDoc.h"
#include "ThreadDemoView.h"
 
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
 
/////////////////////////////////////////////////////////////////////////////
// CThreadDemoView

IMPLEMENT_DYNCREATE(CThreadDemoView, CView)
 
BEGIN_MESSAGE_MAP(CThreadDemoView, CView)
	//{{AFX_MSG_MAP(CThreadDemoView)
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
 
/////////////////////////////////////////////////////////////////////////////
// CThreadDemoView construction/destruction

CThreadDemoView::CThreadDemoView()
{
	// TODO: add construction code here

}
 
CThreadDemoView::~CThreadDemoView()
{
}
 
BOOL CThreadDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}
 
/////////////////////////////////////////////////////////////////////////////
// CThreadDemoView drawing

void CThreadDemoView::OnDraw(CDC* pDC)
{
	CThreadDemoDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}
 
/////////////////////////////////////////////////////////////////////////////
// CThreadDemoView printing

BOOL CThreadDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}
 
void CThreadDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}
 
void CThreadDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}
 
/////////////////////////////////////////////////////////////////////////////
// CThreadDemoView diagnostics

#ifdef _DEBUG
void CThreadDemoView::AssertValid() const
{
	CView::AssertValid();
}
 
void CThreadDemoView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
 
CThreadDemoDoc* CThreadDemoView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CThreadDemoDoc)));
	return (CThreadDemoDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CThreadDemoView message handlers

struct ThreadStruct
{
	CPoint pt;
	CDC dc;
	HWND hWnd;
};
ThreadStruct structure;
 
UINT ThreadProc(LPVOID param);
UNIT ThreadProc(LPVOID param)
{
	structure *s=(structure *)param;
	HDC dc=GetDC(s->hWnd);
	RECT rect;
	HBrush hbr;
	hbr = CreateSolidBrush(RGB(255, 0, 0));
	SelectObject(dc,hbr);
	for(i=0;i<10;i++)
	{
		Ellipse(dc,s->pt.x,s->pt.y,s->pt.x+30,s->pt.y+30);
		Sleep(1000);
	}
	return 0;
}
void CThreadDemoView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	structure.pt=point;
	structure.hWnd=GetSafeHwnd();
	AfxBeginThread(ThreadProc,&point);
	CView::OnLButtonDown(nFlags, &structure.pt);
}
Posted 2-Nov-11 22:57pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You misspelled UINT as UNIT in front of the ThreadProc function.
  Permalink  
Comments
Albert Holguin at 3-Nov-11 10:59am
   
that would explain the error, +5
TABREJ PATEL at 10-Nov-11 1:52am
   
Got it. Thank you...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You also need to make sure you free any GDI resources you use.
 
the thread is calling GetDC() where is the ReleaseDC() call?
Where do you delete the brush object you create?
  Permalink  
Comments
TABREJ PATEL at 10-Nov-11 1:51am
   
Oh.. Yes i forgot to do so. Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 3 Nov 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100