| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | C++ Method Address |
PR> CMOUSE(){ DosCreateThread((&Id_Thread1,
PR> (PFNTHREAD)&cMOUSE::Update, //problems here!!
PR> ThreadArg,ThreadFlags, StackSize);
you should be using _beginthread(), but that won't solve the problem
above. Here's some old messages on the topic:
Area Os2prog, Msg#1994, Jan-10-94 20:17:24
From: James West
To: Russ Lemaster
Subject: Re: Casting pointers to functions for DosCreateThread.
> RL: class ComIO {
> RL: ......
> RL: public:
> RL: ......
> RL: VOID ComEventThread(PVOID *);
> RL: ......
> RL: };
> RL:
> RL: in the init portion, I am using the following to create the thread.
> RL:
> RL: ComIO *MyCom = new ComIO(Port,Buffers,BufferSize);
> RL: TID Thread;
> RL:
> RL: DosCreateThread(&Thread,&MyCom::ComEventThread,0,0,4096);
You're problem is that all class functions have a hidden extra parameter
which is the pointer to the class. The parameters don't match between the
two functions, so the compilers are correctly rejecting the code.
The way I've been doing such things is to use a friend function which I
pass the PVOID * to, and then in the friend function, I cast the PVOID *
over the the class type, and call a class function which isn't a friend.
The parameter in DosCreateThread is an ideal place to pass the address of
the class.
ie:
class tClass {
char lastkbd;
friend void __syscall getkey( unsigned long ul );
void getkey( void );
};
typedef tClass *pClass;
void __syscall getkey( unsigned long dud )
{
(pClass)dud->getkey();
};
void tClass::getkey( void )
{
lastkbd=getch();
};
...
{
unsigned long threadid;
tClass class;
DosCreateThread(&threadid,&getkey,(unsigned long)&class,0,4096);
};
This is fairly similar to what I'm using in my class, although I may have
goofed up somewhere in here. It should be sufficient to get you going
though.
------------------------------------------------------------------------------
Area Os2prog, Msg#477, Dec-27-94 05:05:44
From: Jonathan de Boyne Pollard
To: Ruud Senden
Subject: Threads and classes
//
// ********************************************************************
// A small thread class, showing how threads can be encapsulated as
// class instances, and showing how to use a member function as the
// main function of a thread.
// ********************************************************************
//
// (c) Copyright 1994 Jonathan de Boyne Pollard. All rights reserved.
// Jonathan de Boyne Pollard, FIDONET 2:440/4.0
//
// Permission is hereby granted to post, steal and abuse this code
// for your own purposes to your heart's content, as long as you
// realise that I take no responsibility whatsoever for what it does
// to your machine, data, cat, or marital status.
//
class Thread {
protected:
virtual void main ( void ) = 0 ;
void begin ( unsigned long ) ;
} ;
static
void
run ( void * v )
{
((Thread *)v)->main() ;
}
void
Thread::begin ( unsigned long stack )
{
_beginthread(run, stack, this) ;
}
class MyThread : public Thread {
int per_thread_data1 ;
char per_thread_data2 ;
virtual void main ( void ) ;
public:
MyThread ( int i, char c ) :
per_thread_data1(i),
per_thread_data2(c)
{
begin(4096*64) ;
}
} ;
void
MyThread::main ( void )
{
//
// Put the main code of the thread here. The instance data
// members of the class are "per-thread" data.
//
}
int
main ( int, char ** )
{
MyThread thread2(1, 'g') ;
//
// Do other processing in the main thread
//
}
//
// Of course, the idea is extensible. If another thread needs to
// communicate with an instance of the MyThread class, for example, you
// can write a public member function to do it and initialise all
// relevant semaphores and suchlike in the constructor.
//
> JdeBP <
--- Maximus/2 2.02p1
* Origin: Sol 3/Toronto (905)858-8488 (1:259/414)SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407 SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809 @PATH: 259/414 400 99 250/702 3615/50 396/1 270/101 105/103 42 712/515 @PATH: 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.