By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

cast problem

P: n/a
cdg
I am trying to write a section of code that uses a worker thread and
would need a "post message" to post a
"long" integer to the receiving function. However, I am not sure how to
write the cast for the "long" int. Apparently,
the "long" needs to be a pointer since the thread was passed the "this"
pointer for the main dialog. And the "long" is declared in the main dialog
class. If it is declared as a local variable, there is an Assertion Error
after the program is compiled, and a "Start" button is pushed. This button
starts the thread.

So, could anyone correctly write the "cast" statement that would be
needed for this post message. My C++ is not that versatile yet. And I'm
still learning how to use pointers and cast in most situations.

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

The worker thread section of code:

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

ActxPrg m_ActxPrg; //object declaration

m_ActxPrg.Open(); // open ActxPrg

lResult = m_xActxPrg.MemFunction();

m_ActxPrg.Close(); // close ActxPrg

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

return 0;
}
Jun 16 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
cdg wrote:
I am trying to write a section of code that uses a worker thread and
would need a "post message" to post a
"long" integer to the receiving function. However, I am not sure how to
write the cast for the "long" int. Apparently,
the "long" needs to be a pointer since the thread was passed the "this"
pointer for the main dialog. And the "long" is declared in the main dialog
class. If it is declared as a local variable, there is an Assertion Error
after the program is compiled, and a "Start" button is pushed. This button
starts the thread.

So, could anyone correctly write the "cast" statement that would be
needed for this post message. My C++ is not that versatile yet. And I'm
still learning how to use pointers and cast in most situations.

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

The worker thread section of code:

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

ActxPrg m_ActxPrg; //object declaration

m_ActxPrg.Open(); // open ActxPrg

lResult = m_xActxPrg.MemFunction();

m_ActxPrg.Close(); // close ActxPrg

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

return 0;
}


You don't give us all the information we need. Where is the error
happening? On which line, and if it's on the PostMessage call, what are
the types that PostMessage() expects, and what is the type of each of
the identifiers on that line?

Please note that we don't deal with threading issues here because they
are not (yet) part of Standard C++ language and libraries. For that
reason, you may want to post in a group more applicable to your
platform or compiler. See this FAQ for what is on-topic here and for a
list of possible other groups:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

Cheers! --M

Jun 16 '06 #2

P: n/a
cdg
I believe that this is more of a C++ issue, it just happens to be in
another thread. But the problem is probably just writing a "cast" statement
to convert this:

'long CThreadTestDlg::*' to 'long'

I think this will take care of the problem. However, I am not sure how to
write this type of statement.
Jun 16 '06 #3

P: n/a
cdg wrote:
I believe that this is more of a C++ issue, it just happens to be in
another thread. But the problem is probably just writing a "cast"
statement to convert this:

'long CThreadTestDlg::*' to 'long'

I think this will take care of the problem. However, I am not sure
how to write this type of statement.


This operation is not guaranteed to succeed. A pointer to member can
require more room in memory than a 'long'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 16 '06 #4

P: n/a
cdg wrote:
I believe that this is more of a C++ issue, it just happens to be in
another thread. But the problem is probably just writing a "cast"
statement to convert this:

'long CThreadTestDlg::*' to 'long'

I think this will take care of the problem. However, I am not sure
how to write this type of statement.


On a second thought, make sure you don't forget the parentheses after
the name of the member function.

struct CThreadTestDlg {
long blah() { return 42L; }
};

int main() {
CThreadTestDlg d;
long lo = d.blah; // error similar to what you have
}

Oops... Actually meant

long lo = d.blah();

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 16 '06 #5

P: n/a
cdg
I believe that the problem I am having with this worker thread from the
previous post, is just a class access problem now. And the statements
attempting to access the member functions of this ActiveX class are not
written correctly.
The specifics for this controller function are, it is a static-private
controller thread function of the main dialog class. And I need to access
another class's member function. I have tried creating an object from the
other class, but it causing an Assertion Failure error. So, there must be a
correct way to write this class member access statement.
This statement below is what I have tried, but it does not access the
member function.

m_ActxCtrl.Open(); // open ActxCtrl
Jun 16 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.