Link to home
Start Free TrialLog in
Avatar of shav
shav

asked on

AfxBeginThread prob

Hi all,
I'm a newbie to this whole C++ lark and at the same time I've decided to jump 2 feet first into MFC as well. It's the sink or swim attitude. Anyway I've written a dialog based MFC program and I've come up stumps on starting a new thread. From looking at other posts, I can see people have had the same issue as me, turning a member process into a new thread.
From the other posts I can see that you are only allowed to create a static function or use a global function. That's ok, but if I do either of these, how can I access the rest of the variables in my class? I use an read only edit box, as a form of output for my program. Kinda lost on what steps to take next. Could someone explain in stupid person step, what I need to do. I've tried using the 2 solutions but came into problems, I couldn't access member varibales from static functions, I create a new object of my class but couldn't write to my output, ....
BTW, I found this post which says that it's possible to do it without using static or global functions. However, it's a bit over my head. http://www.codeproject.com/threads/memberthread.asp
Thanks all
Shav
Avatar of Axter
Axter
Flag of United States of America image

Hi shav,
Please post your current code.

What you want to do is call the thread with a pointer to a current instance of your class.
Then your static function takes the generic pointer, and cast it back to a pointer of your class type.

It's easier to show you with your actual code.


Cheers!
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlexFM
AlexFM

Oops, sorry, it is already written in Axter's answer. Please ignore my post.
Avatar of shav

ASKER

Hey Axter, my code is pretty big and don't really want to post.
Could you give me a quick example?
Thanks
           Shav
Avatar of shav

ASKER

This is the test_loop I'm using


UINT CTransmitterDlg::test_loop(LPVOID pParam)
{
      CTransmitterDlg* p = (CTransmitterDlg*) pParam;
      p.output+="in here\r\n";
      return 1;
}

I get the error C2228: left of '.output' must have class/struct/union type when trying to compile
Avatar of shav

ASKER

Thanks guys used p. instead of p->. Working now
Axter, sorry for hijacking your question. If you want these points, you can post request to CS.
>>Axter, sorry for hijacking your question. If you want these points, you can post request to CS.

Don't worry about it.  You earn them. :-)