- Err: illegal call of non-static function
- Posted by schweingruber roland on November 22nd, 2003
Hello
I have some difficulties solving the error message
"error C2352: 'CWnd::MessageBoxA' : illegal
call of non-static member function"
I have a dialog class (CDlg) and a static method
(static void receive()). An other function is creating
a new thread (new thread = receive).
Now I just wanted to call a MessageBox() (see code
below) but then I get the error message. I know what
might be the problem but I cant solve it - can you help
me?
BTW: The receive method must be static. Otherwise
I cannot call it with my _beginthread(receive, 0, (void*)m_pCom);
// begin relevant code
void CDlg::receive(PVOID pvoid){
DevCom *c = new DevCom();
c = (DevCom *)pvoid;
int x = c->getN();
MessageBox("text","title",MB_OK);
}
// end code
- Posted by Tim Robinson on November 22nd, 2003
Use AfxMessageBox or ::MessageBox.
--
Tim Robinson (MVP, Windows SDK)
http://www.themobius.co.uk/
"schweingruber roland" <sg@hotmeil.com> wrote in message
news:3fbfb638$0$3221$5402220f@news.sunrise.ch...
- Posted by r_z_aret@pen_fact.com on November 22nd, 2003
On Sat, 22 Nov 2003 20:17:17 +0100, "schweingruber roland"
<sg@hotmeil.com> wrote:
You are trying to call a non-static function from a static function.
No go (the static function doesn't have access to "this").
Option one (my preference):
Make your receive method a member function, and modify your code so
your thread function gets a pointer to the appropriate object
(instantiation of your class), and can use it to call receive. You can
do this by passing a pointer to the object in the 4th argument to
_beginthread. I actually have use a small structure that includes the
pointer and a bit more info. Whatever is passed as the 4th argument to
_beginthread gets passed as _the_ argument to your thread function.
This looks like a memory leak to me. You created a new object,
assigned a pointer to it, then changed the contents of the pointer. I
think c contains garbage at this point, and you no longer have any way
to delete the DevCom object you just created.
Option two:
::MessageBox( NULL, "text", "title", MB_OK );
The colons at the beginning specify global, which means the Win32 API
itself.
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
Robert E. Zaret
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com
- pure virtual function call (Computers & Technology) by Dave
- How to call activesync's Synchronize function in PPC (Mobile Devices) by nick1332
- How to call bios function in WDM Driver?? (Drivers) by paullee
- ESP not saved across a function call? (Development Resources) by River
- call function twice to succeed? (Development Resources) by Wolfgang

