DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Posts
    70

    Smile Problem using member function when dealing with threading

    :) hi, i am new in programming and now dealing with some multi threading stuff

    anyway i got problem when trying to use member function when doing threads

    i searched around the net and found that 1 method is by using messages which is rather complex

    another method that somebody posted is by casting:

    Code:
    DWORD pg_control::thr ( LPVOID lpvParam ) // static
    {
        pg_control *thr = (pg_control*)lpvParam;
        
        thr->get_hosts(0,NULL);
        // Go on with code ...
        return 0;
    }
    
    
    void pg_control::OnNn()
    {   
       AfxBeginThread (   (AFX_THREADPROC)pg_control::thr,  (LPVOID)this );}


    however i get some errors

    C:\Program Files\Microsoft Visual Studio\MyProjects\abc.cpp(222) : error C2440: 'type cast' : cannot convert from '' to 'unsigned int (__cdecl *)(void *)'
    None of the functions with this name in scope match the target type
    Error executing cl.exe.

    AClient.exe - 1 error(s), 0 warning(s)

    the problem lies in the red text
    can anyone please correct and enlighten me?
    thanks!

    - using winxp programming for win98se
    - MFC style
    - VC++6.0 SP6 :)

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    First of all, you need to add the & operator before pg_control::thr:

    (AFX_THREADPROC)&pg_control::thr
    Secondly, you're using thr both as a function's name and as a local variable. This might confuse the compiler (especially if it's an older one, such as VC++). Finally, make sure that pg_control::thr is a static function. The comment says that it is, but it's worth checking pg_control.h again.
    Danny Kalev

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links