Click here to Skip to main content
15,913,169 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
Generalstd::vector Pin
73Zeppelin9-May-03 15:59
73Zeppelin9-May-03 15:59 
GeneralRe: std::vector Pin
Tim Smith9-May-03 16:36
Tim Smith9-May-03 16:36 
GeneralRe: std::vector Pin
73Zeppelin9-May-03 17:36
73Zeppelin9-May-03 17:36 
GeneralRe: std::vector Pin
John M. Drescher9-May-03 17:00
John M. Drescher9-May-03 17:00 
GeneralRe: std::vector Pin
73Zeppelin9-May-03 17:41
73Zeppelin9-May-03 17:41 
GeneralMFC dialog containing ATL control that fires events... Pin
nebbish8-May-03 9:18
nebbish8-May-03 9:18 
GeneralIE Toolbar in ATL Pin
H.P.8-May-03 8:01
H.P.8-May-03 8:01 
GeneralFireing events from worker thread Pin
Sivakumar R8-May-03 2:08
Sivakumar R8-May-03 2:08 
Hi,

I have written a dll using ATL. In which I want to fire events from a call back function. When I tried to do that my program crashes.

So that I have implemented a hidden window (which I saw in an article in this site) and posting the message to that window. From there I fire the events. It is working quite fine.

But my problem is, when I closes the application which used my COM object, it crashes at the end. I cannot trace what is the problem.

I describe here step by step what I have written in my program..

1. This is the hidden window i have created..

// mywnd.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CMyWindow window
class CClsRecord;
class CMyWindow : public CWnd
{
// Construction
public:
LRESULT OnFireEventForThread(WPARAM wParam, LPARAM lParam);
CClsRecord *m_pControl;
HWND Create();
CMyWindow(CClsRecord *pCtrl);

// Attributes
public:

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyWindow)
protected:
virtual void PostNcDestroy();
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CMyWindow();

// Generated message map functions
protected:
//{{AFX_MSG(CMyWindow)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

HWND CMyWindow::Create()
{
//Register a window class
LPCTSTR classname = 0;
classname = AfxRegisterWndClass(0);

//Create the window and return it's handle
CWnd::CreateEx(NULL,classname,NULL,NULL,1,1,1,1,NULL,NULL);
ASSERT(m_hWnd!=NULL);
return m_hWnd;
}

LRESULT CMyWindow::OnFireEventForThread(WPARAM wParam, LPARAM lParam)
{
CComBSTR bstr;
//This is a one-message-does-everything handler. If wParam is not
//set, that means our message has been sent to fire the even.
//If wParam is set that means we're being asked to destroy ourselves

if(!wParam)
{
if (lParam!=NULL)
{
bstr = m_pControl->GetEventMessage();
m_pControl->Fire_OnEvent(lParam,bstr.Copy());
}
}
else if(wParam==1)
DestroyWindow();
return TRUE;
}

void CMyWindow::PostNcDestroy()
{
//clean up this object
delete this;
}


2. In the ClsRecord class, I have created a thread like this

CMyWindow *pWnd = new CMyWindow(this);
HWND hwndTarget = pWnd->Create();

//create a thread for handling all the events
HANDLE threadHandle = CreateThread(NULL,NULL,
(LPTHREAD_START_ROUTINE)GetNextEventLoopInThread,
(LPVOID)hwndTarget,
NULL,
&Tid);

3. Now, I am sending the message to the window like this..

PostMessage(hWnd,WM_THREADFIREEVENT,(WPARAM)NULL,(LPARAM)CLS_END_CALL_EVENT);


4. Now I call the dll in a VB application. The events are getting fired without any problem. But when I close the vb application, my program crashes. If I use 'End' statement in VB also it crashes immediately.

I have absolutely no glue that what could be the probem? Is it because of a memory leak? Then how can I detect this?

Kindly help me..

Thanks in advance

with regards
Sivakumar R





GeneralRe: Fireing events from worker thread Pin
Ernest Laurentin8-May-03 4:22
Ernest Laurentin8-May-03 4:22 
Questionwriting data to a text file????????? Pin
xxhimanshu8-May-03 1:30
xxhimanshu8-May-03 1:30 
AnswerRe: writing data to a text file????????? Pin
Nick Parker10-May-03 11:38
protectorNick Parker10-May-03 11:38 
GeneralUsing new structure which inherits from Win struc in idl. file Pin
Nena19767-May-03 12:18
Nena19767-May-03 12:18 
GeneralUsing HashSet Pin
Alexandru Savescu7-May-03 2:05
Alexandru Savescu7-May-03 2:05 
GeneralRe: Using HashSet Pin
Joaquín M López Muñoz7-May-03 2:40
Joaquín M López Muñoz7-May-03 2:40 
GeneralRe: Using HashSet Pin
Alexandru Savescu7-May-03 2:56
Alexandru Savescu7-May-03 2:56 
GeneralRe: Using HashSet Pin
Joaquín M López Muñoz7-May-03 3:47
Joaquín M López Muñoz7-May-03 3:47 
GeneralRe: Using HashSet Pin
Alexandru Savescu7-May-03 4:51
Alexandru Savescu7-May-03 4:51 
QuestionHow to return more then one parameters in web control Pin
TianYang6-May-03 17:59
TianYang6-May-03 17:59 
GeneralWTL control Pin
alex.barylski6-May-03 12:05
alex.barylski6-May-03 12:05 
GeneralATL Error when builing release version Pin
Matt Gates6-May-03 10:42
Matt Gates6-May-03 10:42 
GeneralAdding WTL support to existing app Pin
Henrik Husted5-May-03 9:36
Henrik Husted5-May-03 9:36 
GeneralRe: Adding WTL support to existing app Pin
Michael Dunn5-May-03 17:50
sitebuilderMichael Dunn5-May-03 17:50 
GeneralRe: Adding WTL support to existing app Pin
Henrik Husted5-May-03 20:32
Henrik Husted5-May-03 20:32 
QuestionHow can I "cut" a File from a folder/disk drive Pin
Pious4-May-03 21:22
Pious4-May-03 21:22 
AnswerRe: How can I "cut" a File from a folder/disk drive Pin
Sean Cundiff14-May-03 18:04
Sean Cundiff14-May-03 18:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.