🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8463

Re: Threads, Functions and Classes

#8463
From: Remy Lebeau (TeamB)
Date: Tue, 26 Oct 2004 16:29
39 lines
2319 bytes
"Alistair" <Alistair@NoSpam.Sodoff> wrote in message
news:417e2ee6@newsgroups.borland.com...

> [C++ Error] IRCClient.h(200): E2034 Cannot convert 'unsigned long
> (__stdcall * (_closure )(void *))(void *)' to 'unsigned long (__stdcall
*)(void *)'.

You are trying to pass a class method where a non-class standalone function
is expected instead.  To pass a class method in this case, you would have to
declare the method as 'static'.

> I realise its because I have defined the function within my class, but
> I really need it to be defined within my class!!  So how can I get
> around this conversion issue?  This works outstide of a class, but
> I would really like it to work in a class!

Declare the method as static, and then use the method's void* parameter for
passing the class instance's 'this' pointer to the static method so that it
can access the instance as needed:

    class myClass
    {
        bool CreateThread()
        {
            HANDLE Handle = CreateThread(NULL, 0, SocketThread, this,
adtdwFlags, &ThreadID);
            //...
        }

        static DWORD WINAPI SocketThread(LPVOID lpParam)
        {
            myClass *pThis = static_cast<myClass*>(lpParam);
            // use pThis as needed....
        }
    };


Gambit
Technical Details
Message-ID: <417e7b38$3@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!195.5.65.34.MISMATCH!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <417e2ee6@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,fc124e2275bfd1e9
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <417e2ee6@newsgroups.borland.com>
Subject: Re: Threads, Functions and Classes
Date: Tue, 26 Oct 2004 09:29:29 -0700
Lines: 41
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <417e7b38$3@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1098808120 68.69.17.41 (26 Oct 2004 09:28:40 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!195.5.65.34.MISMATCH!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail