cast problem

C

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;
}
 
M

mlimber

cdg said:
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-lite/how-to-post.html#faq-5.9

Cheers! --M
 
C

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.
 
V

Victor Bazarov

cdg said:
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
 
V

Victor Bazarov

cdg said:
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
 
C

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top