multi-thread problem

   I am not sure how to correctly write this Worker Thread example program.
And I realize that this specific problem is somewhat more of a C++ issue.
But I really needed to make sure that I was correctly writing this part of
the program.
   I've also encountered another problem, but I thought it could be
connected with this first problem here. However, I would hoped to ask about
it later.

   How do you write the statement that "post" the long integer in the
Controller thread to the receiving function.

UINT CThreadTestDlg::Thread1(LPVOID lParam)
{
     CThreadTestDlg*  pHwnd = (CThreadTestDlg *)lParam;  //**is this
correct**
     pHwnd->Thread1();
//**is this correct**

   long Num = 123456789;   //need to post this long int

    ::PostMessage((HWND)pHwnd, UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM)Num);
    return 0;
}

LRESULT CThreadTestDlg::OnThreadFinished(UINT wParam, LONG lParam)
{
    return 0;
}

void CThreadTestDlg::OnStart()   //button to start worker thread
{
    AfxBeginThread(Thread1, this);
}


0
anyone78 (134)
6/14/2006 9:33:53 PM
vc.mfc 33608 articles. 0 followers. Follow

23 Replies
813 Views

Similar Articles

[PageSpeed] 16

cdg wrote:
>    I am not sure how to correctly write this Worker Thread example program.
> And I realize that this specific problem is somewhat more of a C++ issue.
> But I really needed to make sure that I was correctly writing this part of
> the program.
>    I've also encountered another problem, but I thought it could be
> connected with this first problem here. However, I would hoped to ask about
> it later.
> 
>    How do you write the statement that "post" the long integer in the
> Controller thread to the receiving function.
> 
> UINT CThreadTestDlg::Thread1(LPVOID lParam)
> {
>      CThreadTestDlg*  pHwnd = (CThreadTestDlg *)lParam;  //**is this
> correct**
>      pHwnd->Thread1();
> //**is this correct**
> 
>    long Num = 123456789;   //need to post this long int
> 
>     ::PostMessage((HWND)pHwnd, UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM)Num);
>     return 0;
> }
> 
> LRESULT CThreadTestDlg::OnThreadFinished(UINT wParam, LONG lParam)
> {
>     return 0;
> }
> 
> void CThreadTestDlg::OnStart()   //button to start worker thread
> {
>     AfxBeginThread(Thread1, this);
> }

You passed 'this' in AfxBeginThread.  The type of 'this' is 
CThreadTestDlg*.  But then in the thread function you named it pHwnd and 
are attempting to use it as an HWND type.  That's wrong: A pointer to a 
dialog is not an HWND.

You have two choices. You can pass 'this' and use the MFC function

   pDialog->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM)Num);

or you can pass the dialog's m_hWnd and use the Win32 function

   ::PostMessage(Hwnd, UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM)Num);

But you can't do some of one and some of the other!!

-- 
Scott McPhillips [VC++ MVP]

0
Scott
6/14/2006 10:45:47 PM
See below...
On Wed, 14 Jun 2006 16:33:53 -0500, "cdg" <anyone@anywhere.com> wrote:

>   I am not sure how to correctly write this Worker Thread example program.
>And I realize that this specific problem is somewhat more of a C++ issue.
>But I really needed to make sure that I was correctly writing this part of
>the program.
>   I've also encountered another problem, but I thought it could be
>connected with this first problem here. However, I would hoped to ask about
>it later.
>
>   How do you write the statement that "post" the long integer in the
>Controller thread to the receiving function.
>
>UINT CThreadTestDlg::Thread1(LPVOID lParam)
>{
>     CThreadTestDlg*  pHwnd = (CThreadTestDlg *)lParam;  //**is this
>correct**
>     pHwnd->Thread1();
>//**is this correct**
>
>   long Num = 123456789;   //need to post this long int
>
>    ::PostMessage((HWND)pHwnd, UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM)Num);
****
Looks good to me...
*****
>    return 0;
>}
>
>LRESULT CThreadTestDlg::OnThreadFinished(UINT wParam, LONG lParam)
****
Why inthe world would you declare the parameters as UINT and LONG?  I am not aware that
there is any place this is documented as being correct.  The CORRECT definition is that
the first parameter is a WPARAM and the second parameter is an LPARAM.  Any other
declaration is erroneous.  This declaration will be fatal when you move to Win64, where
WPARAM and LPARAM are 64 bits, but UINT and LONG are 32 bits.  
>{
****
So now you have your value.  Do someting with it!
****
>    return 0;
>}
>
>void CThreadTestDlg::OnStart()   //button to start worker thread
>{
>    AfxBeginThread(Thread1, this);
>}
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
6/14/2006 11:00:47 PM
  I'm still having problems with this simple worker thread program. And I'm
still not sure how to write the cast for controller function. Could you
correctly write any incorrect statements. And also, I had another question.
I have found that there must be some procedure to correctly place the
message receiving function into the program. Is it placed with the wizard or
manually and static, public or private. And the message maps seem to be
causing some unusual problem. Here is what I've added:

 // Generated message map functions
 //{{AFX_MSG(CThreadTestDlg)
 virtual BOOL OnInitDialog();
 afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
 afx_msg void OnPaint();
 afx_msg HCURSOR OnQueryDragIcon();
 afx_msg void OnStart();
 afx_msg LRESULT OnThreadFinished(UINT wParam, LONG lParam);
 //}}AFX_MSG
 ON_MESSAGE(UWM_THREAD_FINISHED, OnThreadFinished);
 DECLARE_MESSAGE_MAP()
private:
 static UINT Thread1(LPVOID lParam);

   Are there any steps involved in adding these statements. I am getting
these errors:
error C2059: syntax error : '{'
error C2334: unexpected token(s) preceding '{'; skipping apparent function
body

------------------------------------------

  I am getting this error message for code:
error C2660: 'Thread1' : function does not take 0 parameters

UINT CThreadTestDlg::Thread1(LPVOID lParam)
{
 CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;
 pDlg->Thread1();

 long Num = 123456789;

 pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM)Num);
 return 0;
}

LRESULT OnThreadFinished(UINT wParam, LONG lParam)
{
 return 0;
}

void CThreadTestDlg::OnStart()
{
 AfxBeginThread(Thread1, this);
}

-----------------------------------------


0
anyone78 (134)
6/15/2006 2:30:45 AM
"cdg" <anyone@anywhere.com> wrote in message 
news:rE3kg.235123$5Z.45689@dukeread02...
>  I'm still having problems with this simple worker thread program. And I'm
> still not sure how to write the cast for controller function. Could you
> correctly write any incorrect statements. And also, I had another 
> question.
> I have found that there must be some procedure to correctly place the
> message receiving function into the program. Is it placed with the wizard 
> or
> manually and static, public or private. And the message maps seem to be
> causing some unusual problem. Here is what I've added:
>
> // Generated message map functions
> //{{AFX_MSG(CThreadTestDlg)
> virtual BOOL OnInitDialog();
> afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
> afx_msg void OnPaint();
> afx_msg HCURSOR OnQueryDragIcon();
> afx_msg void OnStart();
> afx_msg LRESULT OnThreadFinished(UINT wParam, LONG lParam);

This the wrong signature. Also, I don't think you are supposed to manually 
edit the area between the wizard markers, so I'd suggest moving it outside.

> //}}AFX_MSG
> ON_MESSAGE(UWM_THREAD_FINISHED, OnThreadFinished);

This belongs in the message-map in the *.cpp file.

> DECLARE_MESSAGE_MAP()
> private:
> static UINT Thread1(LPVOID lParam);
>
>   Are there any steps involved in adding these statements. I am getting
> these errors:
> error C2059: syntax error : '{'
> error C2334: unexpected token(s) preceding '{'; skipping apparent function
> body
>

Moving the message-map entry to the message-map will probably fix this.

> ------------------------------------------
>
>  I am getting this error message for code:
> error C2660: 'Thread1' : function does not take 0 parameters
>
> UINT CThreadTestDlg::Thread1(LPVOID lParam)
> {
> CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;
> pDlg->Thread1();
>

Have you declared and implemented such an overload?

-- 
Jeff Partch [VC++ MVP]


0
jeffp (1712)
6/15/2006 2:54:07 AM
See below...
On Wed, 14 Jun 2006 21:30:45 -0500, "cdg" <anyone@anywhere.com> wrote:

>  I'm still having problems with this simple worker thread program. And I'm
>still not sure how to write the cast for controller function. Could you
>correctly write any incorrect statements. And also, I had another question.
>I have found that there must be some procedure to correctly place the
>message receiving function into the program. Is it placed with the wizard or
>manually and static, public or private. And the message maps seem to be
>causing some unusual problem. Here is what I've added:
>
> // Generated message map functions
> //{{AFX_MSG(CThreadTestDlg)
> virtual BOOL OnInitDialog();
> afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
> afx_msg void OnPaint();
> afx_msg HCURSOR OnQueryDragIcon();
> afx_msg void OnStart();
> afx_msg LRESULT OnThreadFinished(UINT wParam, LONG lParam);
> //}}AFX_MSG
> ON_MESSAGE(UWM_THREAD_FINISHED, OnThreadFinished);
**** 
This is erroneous.  The ON_MESSAGE handler will go in your .cpp file, in the message map;
you have erroneously put it someplace totally random, so it is not surprising it doesn't
work.  You need to declare the function
afx_msg LRESULT OnThreadFinished(WPARAM, LPARAM);
where you have the ON_MESSAGE macro.
****
> DECLARE_MESSAGE_MAP()
>private:
> static UINT Thread1(LPVOID lParam);
>
>   Are there any steps involved in adding these statements. I am getting
>these errors:
>error C2059: syntax error : '{'
>error C2334: unexpected token(s) preceding '{'; skipping apparent function
>body
>
>------------------------------------------
>
>  I am getting this error message for code:
>error C2660: 'Thread1' : function does not take 0 parameters
>
>UINT CThreadTestDlg::Thread1(LPVOID lParam)
>{
> CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;
> pDlg->Thread1();
>
> long Num = 123456789;
>
> pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM)Num);
> return 0;
>}
>
>LRESULT OnThreadFinished(UINT wParam, LONG lParam)
>{
> return 0;
>}
>
>void CThreadTestDlg::OnStart()
>{
> AfxBeginThread(Thread1, this);
>}
>
>-----------------------------------------
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
6/15/2006 3:14:45 AM
cdg wrote:
>   I'm still having problems with this simple worker thread program. And I'm
> still not sure how to write the cast for controller function. Could you
> correctly write any incorrect statements. And also, I had another question.
> I have found that there must be some procedure to correctly place the
> message receiving function into the program. Is it placed with the wizard or
> manually and static, public or private. And the message maps seem to be
> causing some unusual problem. Here is what I've added:
> 
>  // Generated message map functions
>  //{{AFX_MSG(CThreadTestDlg)
>  virtual BOOL OnInitDialog();
>  afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
>  afx_msg void OnPaint();
>  afx_msg HCURSOR OnQueryDragIcon();
>  afx_msg void OnStart();
>  afx_msg LRESULT OnThreadFinished(UINT wParam, LONG lParam);
>  //}}AFX_MSG
>  ON_MESSAGE(UWM_THREAD_FINISHED, OnThreadFinished);

This line belongs in the message map (in the cpp file).


>  DECLARE_MESSAGE_MAP()
> private:
>  static UINT Thread1(LPVOID lParam);

This line declares Thread1 with a parameter.

> 
>    Are there any steps involved in adding these statements. I am getting
> these errors:
> error C2059: syntax error : '{'
> error C2334: unexpected token(s) preceding '{'; skipping apparent function
> body
> 
> ------------------------------------------
> 
>   I am getting this error message for code:
> error C2660: 'Thread1' : function does not take 0 parameters
> 
> UINT CThreadTestDlg::Thread1(LPVOID lParam)
> {
>  CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;
>  pDlg->Thread1();

This line calls a Thread1 function that does not have a parameter.  It 
does not match your declarations.  The compiler error message appears to 
be clear and correct.  It is hard to understand why you don't understand 
this error: You are calling a function that you have not declared.

> 
>  long Num = 123456789;
> 
>  pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM)Num);
>  return 0;
> }
> 
> LRESULT OnThreadFinished(UINT wParam, LONG lParam)


This line's parameters do not match your declarations.


> {
>  return 0;
> }
> 
> void CThreadTestDlg::OnStart()
> {
>  AfxBeginThread(Thread1, this);
> }
> 
> -----------------------------------------
> 
> 

-- 
Scott McPhillips [VC++ MVP]

0
Scott
6/15/2006 3:39:33 AM
   I believe your suggestions corrected the problems I was having with the
message maps and adding the code. However, I am still getting the one error
message. And no there is no overloaded function in the program. But I am
still not sure how to correctly write the cast for the "this" pointer. If
you could correctly write those statements it sure would help.

error C2660: 'Thread1' : function does not take 0 parameters

For this section of code:

UINT CThreadTestDlg::Thread1(LPVOID lParam)
{
 CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;
 pDlg->Thread1();

 long Num = 123456789;

 pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM)Num);
 return 0;
}


0
anyone78 (134)
6/15/2006 3:45:50 AM
   I got these lines (below) from Joseph's site, and apparently I don't
understand how it was to be used in the controller. And my C++ is not that
versatile yet. And I'm still learning how to use pointers in most
situations.

CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;
>  pDlg->Thread1();

  Could you correctly write this statement for how it is required in this
simple Test program.


0
anyone78 (134)
6/15/2006 4:00:03 AM
"cdg" <anyone@anywhere.com> wrote in message 
news:LK4kg.235127$5Z.82577@dukeread02...
>   I believe your suggestions corrected the problems I was having with the
> message maps and adding the code. However, I am still getting the one 
> error
> message. And no there is no overloaded function in the program. But I am
> still not sure how to correctly write the cast for the "this" pointer. If
> you could correctly write those statements it sure would help.
>
> error C2660: 'Thread1' : function does not take 0 parameters
>
> For this section of code:
>
> UINT CThreadTestDlg::Thread1(LPVOID lParam)
> {
> CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;
> pDlg->Thread1();
>

Well, its simple really. To call the member function 
CThreadTestDlg::Thread1(), Your CThreadTestDlg class needs to have such a 
member function. Does it?
-- 
Jeff Partch [VC++ MVP]


0
jeffp (1712)
6/15/2006 4:02:54 AM
cdg wrote:
>    I believe your suggestions corrected the problems I was having with the
> message maps and adding the code. However, I am still getting the one error
> message. And no there is no overloaded function in the program. But I am
> still not sure how to correctly write the cast for the "this" pointer. If
> you could correctly write those statements it sure would help.
> 
> error C2660: 'Thread1' : function does not take 0 parameters
> 
> For this section of code:
> 
> UINT CThreadTestDlg::Thread1(LPVOID lParam)
> {
>  CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;
>  pDlg->Thread1();
> 
>  long Num = 123456789;
> 
>  pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM)Num);
>  return 0;
> }

The cast for the 'this' pointer is not related to the error.

Can you show us the function you are trying to call, and show us its 
declaration in the header?

The error message implies that you are trying to call a function you 
don't have.  It looks like you need this line added to the class 
declaration:

   void Thread1();

And then, of course, you have to provide the function.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
6/15/2006 5:24:59 AM
   All I am trying to do is create a worker thread and send the appropiate
handle. And then correctly "post" a message to the receiving function. And
right now I am really not concerned about what is posted in the message.
Also,  I haven't used pointers very much.

  Is the line below correctly written?

CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;

  If so, how do I use it in a statement to post this test variable "Num" to
the receiving function. Or it that all that is required. Below is the code
for the controller function.

UINT CThreadTestDlg::Thread1(LPVOID lParam)
 {
     CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;

     long Num = 123456789;

     pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM)Num);

     return 0;
}




0
anyone78 (134)
6/15/2006 2:39:12 PM
cdg wrote:
>    All I am trying to do is create a worker thread and send the appropiate
> handle. And then correctly "post" a message to the receiving function. And
> right now I am really not concerned about what is posted in the message.
> Also,  I haven't used pointers very much.
> 
>   Is the line below correctly written?
> 
> CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;
> 
>   If so, how do I use it in a statement to post this test variable "Num" to
> the receiving function. Or it that all that is required. Below is the code
> for the controller function.
> 
> UINT CThreadTestDlg::Thread1(LPVOID lParam)
>  {
>      CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;
> 
>      long Num = 123456789;
> 
>      pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM)Num);
> 
>      return 0;
> }

This code is correct and is all that is required, if:
  - the dialog 'this' pointer is being passed as the lParam.
  - this Thread1 function is declared with 'static'.
Do you have a problem when you use this code?

-- 
Scott McPhillips [VC++ MVP]

0
Scott
6/15/2006 3:16:59 PM
  This code below is the main idea for this simple Test program. And it does
compile now and work correctly. However, is there a way to post this "long
int" back to the start function, and not have the OnThreadFinished function.
Or would there be a problem with doing that.

UINT CThreadTestDlg::Thread1(LPVOID lParam)
{
 CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;

 long Num = 123456789;

 pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM)Num);

 return 0;
}

LRESULT CThreadTestDlg::OnThreadFinished(WPARAM wParam, LPARAM lParam)
{
 CString s;
 s.Format("%d", Num);
 m_cResult.SetWindowText(s);

 return 0;
}

void CThreadTestDlg::OnStart()  //start button
{
 AfxBeginThread(Thread1, this);
}


0
anyone78 (134)
6/15/2006 3:26:01 PM
cdg wrote:
>   This code below is the main idea for this simple Test program. And it does
> compile now and work correctly. However, is there a way to post this "long
> int" back to the start function, and not have the OnThreadFinished function.
> Or would there be a problem with doing that.

Happy you got it working!

There would be several problems with posting the result back to the 
start function.  The GUI thread would have to suspend (freeze) to wait 
for the result.  So you would not really have multithreading.  And while 
the main thread is suspended user input and screen refresh would stop 
working.  If it suspends too long it causes a "The application is 
failing to respond" message to be displayed to the user.  The purpose of 
a worker thread like this is to let your GUI thread continue to process 
messages to keep the GUI alive while the worker thread does some 
time-consuming task.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
6/15/2006 5:09:12 PM
   I got the initial Example program working, but now I am not sure how to
write a "cast" to access a member function in an ActiveX Class. I have
already made an Example program testing this ActiveX Control and it worked.
But in this worker thread, I am not sure how to write this. Also, the dot
operators are in the code below, but they are hard to see.

UINT CThreadTestDlg::Thread1(LPVOID lParam)
{
 CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;

 m_xActxCtrl.Open();   // open ActxCtrl

 lResult = m_xActxCtrl.MemFunction();

 m_xActxCtrl.Close();   // close ActxCtrl

 pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM) lResult);

 return 0;
}


0
anyone78 (134)
6/15/2006 11:28:20 PM
   I think I got the code correctly written for the problem in the previous
post. I just created an object of the ActiveX class. However, I am getting
one error message now,  that I am not sure how to correct. It is a problem
with the function being "static", and involving the result from the ActiveX
Prg.

error: illegal reference to data member 'CThreadTestDlg::lResult' in a
static member function

UINT CThreadTestDlg::Thread1(LPVOID lParam)
{
 CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;

ActxCtrl m_xActxCtrl; //****Added this line****

 m_xActxCtrl.Open();   // open ActxCtrl

 lResult = m_xActxCtrl.MemFunction();

 m_xActxCtrl.Close();   // close ActxCtrl

 pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM) lResult);

 return 0;
}



0
anyone78 (134)
6/16/2006 12:32:02 AM
cdg wrote:
>    I think I got the code correctly written for the problem in the previous
> post. I just created an object of the ActiveX class. However, I am getting
> one error message now,  that I am not sure how to correct. It is a problem
> with the function being "static", and involving the result from the ActiveX
> Prg.
> 
> error: illegal reference to data member 'CThreadTestDlg::lResult' in a
> static member function
> 
> UINT CThreadTestDlg::Thread1(LPVOID lParam)
> {
>  CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;
> 
> ActxCtrl m_xActxCtrl; //****Added this line****
> 
>  m_xActxCtrl.Open();   // open ActxCtrl
> 
>  lResult = m_xActxCtrl.MemFunction();
> 
>  m_xActxCtrl.Close();   // close ActxCtrl
> 
>  pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM) lResult);
> 
>  return 0;
> }
> 
> 
> 

As you have learned, the thread function must be static.  This is 
required by the operating system.

A static function cannot access class members.  This is a required by 
the C++ language.  But lResult is a class member.

In your above trivial problem it appears that there is no need to have 
lResult be a class member.  So make it a local variable instead.

The more general solution to the static thread function needing access 
to class members was illustrated in the example you tried to copy 
earlier, that used pDlg->Thread1().  But I don't think you understood 
the technique, so it is best avoided for now if you can.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
6/16/2006 2:28:26 AM
   I had tried earlier, before I read your post, to make the "long int"
variable local and it did compile. But now, whenever the "Start" button is
clicked, there is an "Assertion Failed" error. The same code is below with
the newer changes.

UINT CThreadTestDlg::Thread1(LPVOID lParam)
{
 CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;

ActxCtrl m_xActxCtrl;

 m_xActxCtrl.Open();   // open ActxCtrl

 long lResult = m_xActxCtrl.MemFunction();

 m_xActxCtrl.Close();   // close ActxCtrl

 pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM) lResult);

 return 0;
}


0
anyone78 (134)
6/16/2006 2:48:34 AM
   It didn't correct the problem by just making this variable " lResult "
local, so I've changed it back and this is the error message for it.

error C2440: 'type cast' : cannot convert from 'long CCThreadTestDlg::*' to
'long'

The code now:

UINT CThreadTestDlg::Thread1(LPVOID lParam)
{
 CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;

ActxCtrl m_xActxCtrl;

 m_xActxCtrl.Open();   // open ActxCtrl

 lResult = m_xActxCtrl.MemFunction();

 m_xActxCtrl.Close();   // close ActxCtrl

 pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM) lResult);

 return 0;
}


0
anyone78 (134)
6/16/2006 8:04:11 AM
cdg wrote:
>    It didn't correct the problem by just making this variable " lResult "
> local, so I've changed it back and this is the error message for it.

But changing the variable to local did correct the problem.  You said so 
yourself: "it did compile."  That is good progress.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
6/16/2006 1:05:00 PM
cdg wrote:
>    I had tried earlier, before I read your post, to make the "long int"
> variable local and it did compile. But now, whenever the "Start" button is
> clicked, there is an "Assertion Failed" error. The same code is below with
> the newer changes.
> 
> UINT CThreadTestDlg::Thread1(LPVOID lParam)
> {
>  CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;
> 
> ActxCtrl m_xActxCtrl;
> 
>  m_xActxCtrl.Open();   // open ActxCtrl
> 
>  long lResult = m_xActxCtrl.MemFunction();
> 
>  m_xActxCtrl.Close();   // close ActxCtrl
> 
>  pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM) lResult);
> 
>  return 0;
> }

Assertion failures give you information about which line of your code 
led to the problem, and the exact MFC code and function that asserted. 
But you have not provided any of that information.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
6/16/2006 1:09:52 PM
   I think the problem can be corrected with a simple cast statement. And I
believe it is more of C++ issue, but I haven't used cast myself in some of
the C++ I've written so far except for this MFC program. I am learning and
would like to understand how to write the cast for this situation. I need to
convert from the main dialog to this "long int" from the ActiveX class. And
that is what I am not understanding. Could the cast be written as simple as
this statement:

 CThreadTestDlg*  pNum = ( m_xActxCtrl *)long pNum;

--------------------------------------------

error C2440: 'type cast' : cannot convert from 'long CThreadTestDlg::*' to
'long'

-------------------------------------------
The code written with the above statement:

UINT CThreadTestDlg::Thread1(LPVOID lParam)
{
 CThreadTestDlg*  pDlg = (CThreadTestDlg *)lParam;
CThreadTestDlg*  pNum = ( m_xActxCtrl *)long pNum;

ActxCtrl m_xActxCtrl;

 m_xActxCtrl.Open();   // open ActxCtrl

 pNum = m_xActxCtrl.MemFunction();

 m_xActxCtrl.Close();   // close ActxCtrl

 pDlg->PostMessage(UWM_THREAD_FINISHED, (WPARAM)0, (LPARAM) pNum);

 return 0;
}

  I haven't tried this code yet, but I'll see how it goes.



0
anyone78 (134)
6/16/2006 1:53:35 PM
   I found out that the code in the previous post does not work. However, I
believe the problem can easily be resolved if I understood how to write the
"cast" for the "long" that is produced by the ActiveX Prg. Then the
converted variable can be used in the "post" message. It must have to
converted to pointer to "post" to the receiving function of the message.


0
anyone78 (134)
6/16/2006 3:56:56 PM
Reply:

Similar Artilces:

multi-column data consolidation
Hi guys, here is my problem.... Scenario: - Column A to F are months (Jan to June) - Beneath each month (starting row 2 downwards), text data will b entered. Question: How can I have the six months add up or compiled as a single colum database in another sheet or a separate column in that same sheet? will be adding data every so often under these months and it shoul update the database. Thank you for any assistance/help -- Message posted from http://www.ExcelForum.com Question is not clear to me. Not sure what 'add up or compile' means with text entries Perhaps, in G2 enter =...

Publisher 2007 Booklet Print Problem
I created a small 4 pg booklet using a designed template from MS online. This is a 1/2 booklet format 5.5 x 8.5; I set all margins to 1/4" in the master and page set up. I successfully insert my pics & bled them to the edge of the sheet. The problem comes with printing samples on my HP PSC 1350 home printer. I lose 1/2" of printing on the front edge of pg 1 & pg 3; meaing that for 1/2" from the edge.. it is blank and my full image doesn't print fully. I want to bleed all the images to the edge and use printed sample pages or send a pdf to the printer for fi...

Character Problem
Hi Everyone, Here is another thing that I can't figure out. I am writing a text to a file File.WriteString(_T("2 x 3 = 6 3 x 2 = 6 6 � 2 = 3 6 � 3 = 2.\n")); But when I read it back I get 2 x 3 = 6 3 x 2 = 6 6 2 = 3 6? 3 = 2 I am not sure why the � (character 0xF7) is not showing up correctly? The funny thing is that the first one doesn't even show up, and the second one shows up as a block. Any solution to this? Ali Hi Ali, Looks like a font problem, but is the character in question stored in the file correctly? And are the proper chars in ...

Problem with DECLARE CURSOR
Dear Sir, I am using SQL Server 2005, Visual Basic 6 (SP6) & Microsoft ActiveX Data Object 2.5. If I run following query through SQL Server 2005 Management Studio through QUERY only then it works FINE. But if I run from application using Execute method of Command Object of ADO then it process maximum 49 records in CURSOR and query completes without any errors. I had checked by inserting records in a Temporary Table. If I do Not Use UPDATE statement then it INSERT maximum 65 records in Table and if I use UPDATE statement then it INSERT & UPDATE maximum 49 records. ...

Problems with hyperlinks
I hope I can explain this well enough for everyone to understand. Here goes: I am using Excel 2003. I have a workbook that has approx. 2,300 Rows of data. Within each row there are 4 Columns that contain different hyperlinks that go to corporate websites. I have come across some errors where the hyperlinks are going to the wrong URL. Sometimes when I click the ‘Insert Hyperlink’ button and ‘Remove Hyperlink’, I find that when I go to relink the cell, it still has another hyperlink even though I just removed one. It’s like there were two different hyperlinks in one cell. How does...

Multi profile
I have configured outlook 2007 to use multi profiles. When I close the outloop and re-open to select other profile the profiles select list is not prompted. I have set for prompt for profile. But I observed this, after closing outlook still the task manager shows Outlook.exe is runing..when I kill that and re-open I can see the profiles and select particular. Now my question, why Outlook is runnning though its closed. My setting "Hide when minimized" is already OFF. thanks Hi abcd, have a look in the "Task Manager" under "Process" if Outlook.exe is stil...

A question about thread,please help me #2
My program environment is .net2005.The partial code is shown as below: void CfinalView::OnRButtonDblClk(UINT nFlags, CPoint point) { CRect rc; GetClientRect(&rc); if(point.x>rc.left&&point.x<(rc.right/2)&&point.y>rc.top&&point.y<rc.bottom) { //AfxBeginThread(RUNTIME_CLASS(CDetailPlot)); } if(point.x>(rc.right/2)&&point.x<rc.right&&point.y>rc.top&&point.y<(rc.bottom/2)) { //AfxMessageBox(_T("haha")); AfxBeginThread(RUNTI...

Saving Files Problem
I have been using Excel at work to do simple spreadsheets. When I wan to take some data home to enter, I saved this info on a 3.5 diskette When I try to open it at work I get a message that this file cannot b accesssed. I am using the same systems on both machines.( Excel 2000.) The message says " the file is either read-only or you may be trying t acess a read-only location. Or, the server the document is stored on i not responding" Any Suggestions -- Message posted from http://www.ExcelForum.com Terry, Never work directly in Excel from/to a diskette. There are many documented ...

Problems with Office 2004
All of a sudden I am having problems loading Office 2004 applications. When I try to load them it says "The Application (Word, Entourage, Excel, Power Point) quit unexpectedly." I am given the option of "close", "report" or "reopen". I have found I have to choose "reopen" at which time the I get the message "the application Excel quit unexpectedly after it was reopened". I can then "close" "Try Again" or "Report". If I say Try Again it finally opens. I have reported it and even deleted the programs ...

Problem with Microsoft excel reports
We are implementing a project on Microsoft CRM 3.0. I have developed a report in Microsoft Excel using Microsoft Query. I have uploaded the same on CRM in the Reports section. The problem is when I open the report from the Reports section, the CRM web instance closes. Is there a solution for the same? On top of separate connection issues, I suffered the same problem last week. I'm going to look for a KB article today top see if this is a documented issue. I'll keep you posted if I find something. Do you have the Update Rollup 1 installed? "Anu" wrote: >...

Problem with WMC for Win7 x64 -- live TV setup problem
When I try to setup WMC (Win7 x64) for live TV it goes through the region setting question, then the zip code, then when it goes to "configuring" it hangs. I got a tip to run "mcupdate.exe" from another forum to overcome the hanging. After is scans for channels it asks if ATSC digital is what I want (I do, for OTA TV)... then comes this dreaded screen: http://i49.tinypic.com/2qb5dac.jpg "TV setup has encountered a serious problem. Select Finish to exit, then try again. If this problem persists, restart Windows Media Center or the computer." I&...

Problem exporting/importing .psf
Hi guys, I searched the community before and couldn't find anything regarding this issue. I am trying to export an Outlook 2000 mailbox from one user account to another. However, when I try and import it, I get the message saying that "Personal Folders "Properties for this information service must be defined prior to use". I have looked up solutions for this and they say to make sure its not read only. I tried this and it doesnt work, its currently NOT read only. Please note: This is a computer where the Outlook folder source for the export is on a user account no...

Mac Stuff CDs, A to Z, updated 15/Jan/2006, and Win & Mac programs, 'WinMac', 'PC/MaC', 'Win-Mac', 'Multi', 'Multi-Platform', 'MultiFormat', 'MULTIOS', 'HYBRID'
Mac Stuff CDs, A to Z, updated 15/Jan/2006, and Win & Mac programs, 'WinMac', 'PC/MaC', 'Win-Mac', 'Multi', 'Multi-Platform', 'MultiFormat', 'MULTIOS', 'HYBRID' GARAGE SALES, buy, risk-free purchase, working, tested, fully functional, very cheap discounted price, low cost, quality OEM software, -------------------------------------------------------- Abvent Artlantis v4.5 Mac 1CD Abvent.PhotoCAD.v1.0.MacOSX ACD.Systems.Canvas.X.0.2.925.MacOSX Adobe.Acrobat.7.0.Pro.for.Mac.OS 1CD Adobe Acrobat 6.0.0 Professional Mac OSX 1CD ...

Registry problem
I recently had to reinstall xp and always change the registry so that the number lock is always on as below. I find now since the reinstall the registry won't keep the changes for HKEY_USERS, does anyone have a suggestion? thanks HKEY_USERS\.DEFAULT\Control Panel\Keyboard >InitialKeyboardIndicators = 0 > >HKEY_CURRENT_USER\Control Panel\Keyboard >InitialKeyboardIndicators = 0 Isn't there a setting in the Bios for that? If you enabled it stay on it will. "JT" <grouch_45@hotmail.com> wrote in message news:Swldn.9717$4N4.1...

problems with Outlook client running on the Window2000
Hi guys, My Outlook client runs on Windows2000 SP4 and IE SP1 , office2003. now, there is a serious problem which the IE will appear the message "the page can not be displayed correctly", when i save the e-mail activity in the outlook client. does any one know how to fix it? Jerry ...

Version problem
I've seen that others have a problem opening Publisher files from different versions so it's a popular request, but I'm trying to open a file and I'm not sure what version it was made in (I think 95). I need it for Publisher 2000. Would someone be willing to convert it for me? Thanks, mm I'll convert it, be aware you may lose some formatting. gsauer at columbus dot rr dot com -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "matmorris" <matmorris@discussions.microsoft.com> wrote in message news:0...

problem view causes amt to invoice and price extension not to update in sales order entry
I created a view with an index and it caused some odd behaviors in Sales Order Entry. The quantity to invoice no longer updated when I tabbed off the quantity field and also the price extension didn't compute either. Once I deleted the view, the problem went away. Here is the view & index T-SQL. Scott Emick USE [WINDY] GO /****** Object: View [dbo].[gvaWholeSaleInventoryPrices] Script Date: 09/29/2008 09:24:23 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER VIEW [dbo].[gvaWholeSaleInventoryPrices] WITH SCHEMABINDING AS SELECT INVENTORY.ITEMNMBR, CASE PRICMTHD W...

SFO problems 02-21-06
Re-posting because i didnt get a response. Can someone please help?? Matt, John, anyone??? We have developed a custom multiselect lookup in .net. This .net page is called from an iframe inside the entity form. This works fine on the server. However, when we deploy this code on SFO (we have copied the project folder and created a virtual directory on the SFO client machine), an alert message saying "access is denied" is popping up. Can someone please help with this???? CRM 3.0; SQL 2000; VS.NET 2003. Looking to upgrade to SQL 2005 and VS.NET 2005 Good chance it has something ...

threads won't close and then reopen correctly...
I have a MFC VC++ project that has a thread started in the OnInitDialog() function of a dialog box. AfxBeginThread(ThreadProcess, (LPVOID) this, 0); I handle the thread in the the following function UINT Questions::ThreadProcess(LPVOID param) { //do some stuff AfxEndThread(0); return 0; } Everything works well until I close the dialog box and then reopen it. When I do that the thread doesn't work as it should the second time around. Anyone have any thoughts on why I am getting this unwanted behavior and what I can do to correct it? Thanks in advance, RABMissouri2008 "RAB&...

Multi-threading with multi-port server
Hi guys, Can I ask your guidance on how to imeplement server with multi- threading and multi-port? meaning, I would like my server to receive audio and video in different ports, and they run concurrently and send the data to clients. I am so lost, because I would mess up my .accept and .listen and setparent if i have videosocket and audiosocket object. I tried and it just froze. "Rehmet" <rgnurrahmat@gmail.com> wrote in message news:8f9b7615-8252-4661-9949-8812b735aa00@l32g2000hse.googlegroups.com... > Hi guys, > > Can I ask your guidance on how to imeplement serve...

Calender Problem after Exchange Migration
Hi all, I've got a bit of a Exch Calendar problem. We recently migrated from Exch2000 Srv to Exch2003 Srv. We also changed domain names (AD and company) as well. Due to time constraints and other issues I won't go into, things were a little rushed and the way we did the migration was probably not by the MS rules. Basically we restored a backup of the mailboxes from the old Exch2000 server to the new Exch2003 server. This was done via Qinetix MB idata agent. We thought this would be quicker than exporting the mailbox's out as PST files and then importing them. This part app...

Can't open the link to a reply to a thread I posted
Hi Everyone, I received a reply to a question RE Excel/Office, but when I try to open the link, the page except for the header is blank. Have you ever had that happen, and what can I do to fix it? I really appreciate the help and goodwill that you send my way. Hopefully, I can reciprocate, somewhere. RkyMtn. "RkyMtn" <RkyMtn@discussions.microsoft.com> wrote in message news:CBAFD12E-DA58-454D-8241-79B95002394C@microsoft.com... > Hi Everyone, I received a reply to a question RE Excel/Office, but when I > try > to open the link, the page except for the header is bla...

A little Excel Problem.
Can I hide negitive but not posivtive values in cells? Using Conditional Formatting (Format>Conditional formatting...) set the cell value to less than 0 and set the font format to white (Presuming no colour in cell background... if there is use this colour). The data will still be there but invisible. It will print though -- HTH Nick Hodge Microsoft MVP - Excel Southampton, England www.nickhodge.co.uk nick_hodgeTAKETHISOUT@zen.co.uk.ANDTHIS "Qallupilluq" <Qallupilluq@discussions.microsoft.com> wrote in message news:E8D652F9-0EF8-44CA-B711-1965F49005BE@microsoft.co...

Problem with InvalidateRect
I am trying to play a video in a MFC application using a view. To display frames quickly I have to call InValidateRect() so that the new frame gets painted. My view is getting updated perfectly but my other controls on the view like buttons or toolbar buttons are either not displayed or either are shown disabled even when I have written code to enable them. If I remove InvalidateRect then everything works fine but my view does not get refreshed and hence I cannot see the video. Is there any way to solve this problem or Is there any other option for InvalidateRect? Thanks and Regards, Rishi. ...

Multi Store Workflow Question
We have one store and a warehouse. We need to order and receive items at the warehouse and transfer them to the store. We need the store to be able to see what is on order and all inventory at the warehouse. Is anyone doing something like this, and how easy it it? At a recent demo, this required many steps, logging into 3 different databases, doing updates, etc. Very confusing for simple tasks we need to do every day. Marvin: Microsoft RMS HeadQuarters would be the solution for you. You can view the inventory in Warehouse and items on order from the Store Mihir Shah Diviasoft, In...