Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Thread question??

Thread question??

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
23 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Ahmed Charfeddine

    1- I should be wrong 2- I should be always treated and faced with interventions like yours 3- I should suffer from the most punishment for persisting not to clear my behaviour and at least accept the fact that if I have to tell someone something, or that if I have to help him, then I have to speak properly, explain with evidence , and not throw an answer or a solution in a way that make the person not believe in it or hesistate to believe that it will solve his problem. 4- I have problem with myself as you can see becvuase you are intelligent. 5- I am correct (not to your disappointment of course). So here I created a sample MFC Dlg project, and I created a memberfunction of the main dialog class (CThreadQuestionDlg) which is passed as parameter to teh createThread function somewhere in order to be executed by that would-be-thread. I coded the function such it access the m_list member of the dialog class in two ways :

    // ThreadQuestionDlg.h : header file
    //

    #pragma once
    #include "afxcmn.h"

    // CThreadQuestionDlg dialog
    class CThreadQuestionDlg : public CDialog
    {
    // Construction
    public:
    CThreadQuestionDlg(CWnd* pParent = NULL); // standard constructor

    // Dialog Data
    enum { IDD = IDD_THREADQUESTION_DIALOG };

    protected:
    virtual void DoDataExchange(CDataExchange\* pDX);	// DDX/DDV support
    

    // Implementation
    protected:
    HICON m_hIcon;

    // Generated message map functions
    virtual BOOL OnInitDialog();
    afx\_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx\_msg void OnPaint();
    afx\_msg HCURSOR OnQueryDragIcon();
    DECLARE\_MESSAGE\_MAP()
    

    public:
    CListCtrl m_list;

    //
    static UINT ThreadProc(LPVOID pParam)
    {
    	CThreadQuestionDlg\* pMe = reinterpret\_cast<CThreadQuestionDlg\*>(pParam);
    	pMe->m\_list.DeleteAllItems();  /\*This is the case number 1\*/
    	//m\_list.DeleteAllItems();   /\*This is the case number 2\*/
    	return 0;
    }
    void StartThread()
    {
    	AfxBeginThread(ThreadProc, this);
    }
    

    };

    Look at the code and you will find two particular lines within the ThreadProc member. If we keep things as they are there are no problems. But if We uncomment the case number 2 and we comment the case number 1 Then soon when we try to compile we get C2228 compilation code errors ! 1>Compiling... 1>ThreadQuestionDlg.cpp 1>c:\documents and settings\administrateur\mes documents\visual studio 2005\projects\threadquestion\threadquestion\threadquestiondlg.h(44) : error C2228: left of '.DeleteAllItems' must have class/str

    S Offline
    S Offline
    Saurabh Garg
    wrote on last edited by
    #8

    Wow you have some serious issues!!!

    hINTModuleState wrote:

    CListCtrl m_list; // static UINT ThreadProc(LPVOID pParam) { CThreadQuestionDlg* pMe = reinterpret_cast(pParam); pMe->m_list.DeleteAllItems(); /*This is the case number 1*/ //m_list.DeleteAllItems(); /*This is the case number 2*/ return 0; } void StartThread() { AfxBeginThread(ThreadProc, this); }

    Uncommenting second case will lead to compiling error because ThreadProc is a static function and a static function can only access static members of a class. Since m_list is not a static variable you cannot access it directly from with the function. For you profiling needs try http://www.codeproject.com/KB/datetime/perftimer.aspx[^] Saurabh

    A 1 Reply Last reply
    0
    • H Hamid Taebi

      Can you show your code and it seems you forgot to include header file or your program?

      Y Offline
      Y Offline
      york528
      wrote on last edited by
      #9

      the Thread function is global function CCriticalSection m_Sec; is global too now after include atlbase.h only error C2065: 'ReadDirectoryChangesW' : undeclared identifier

      1 Reply Last reply
      0
      • E Eytukan

        Basix. 1.include atlbase.h 2.You cannot access member variables from a static thread function. Pass the this(Dlg) pointer into the thread param and access it inside the function or do it in one of the 100 ways.


        OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus Best wishes to Rexx[^]

        Y Offline
        Y Offline
        york528
        wrote on last edited by
        #10

        after include atlbase.h only error C2065: 'ReadDirectoryChangesW' : undeclared identifier do i miss other head file??

        E 1 Reply Last reply
        0
        • D David Crow

          york528 wrote:

          error C2065: 'USES_CONVERSION' : undeclared identifier

          See here.

          york528 wrote:

          error C2065: 'ReadDirectoryChangesW' : undeclared identifier

          See here.

          york528 wrote:

          error C2065: 'm_list' : undeclared identifier

          See here. What does any of what you posted have to do with threads?

          "Love people and use things, not love things and use people." - Unknown

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          Y Offline
          Y Offline
          york528
          wrote on last edited by
          #11

          there's only one problem error C2065: 'ReadDirectoryChangesW' : undeclared identifier after i do the follow Header Declared in WinBase.h; include Windows.h. it's still have the problem

          1 Reply Last reply
          0
          • H Hamid Taebi

            Can you show your code and it seems you forgot to include header file or your program?

            Y Offline
            Y Offline
            york528
            wrote on last edited by
            #12

            i did nothing the code dosen't changed but the m_list problem solved :confused::confused::confused:Amazing

            1 Reply Last reply
            0
            • Y york528

              after include atlbase.h only error C2065: 'ReadDirectoryChangesW' : undeclared identifier do i miss other head file??

              E Offline
              E Offline
              Eytukan
              wrote on last edited by
              #13

              define this :

              #define _WIN32_WINNT 0x400

              in stdafx.h. What OS are you using?


              OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus Best wishes to Rexx[^]

              Y 1 Reply Last reply
              0
              • E Eytukan

                define this :

                #define _WIN32_WINNT 0x400

                in stdafx.h. What OS are you using?


                OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus Best wishes to Rexx[^]

                Y Offline
                Y Offline
                york528
                wrote on last edited by
                #14

                windows XP thank you so much #define _WIN32_WINNT 0x400 what's that for i am new and my English is not so good

                E 1 Reply Last reply
                0
                • D David Crow

                  york528 wrote:

                  error C2065: 'USES_CONVERSION' : undeclared identifier

                  See here.

                  york528 wrote:

                  error C2065: 'ReadDirectoryChangesW' : undeclared identifier

                  See here.

                  york528 wrote:

                  error C2065: 'm_list' : undeclared identifier

                  See here. What does any of what you posted have to do with threads?

                  "Love people and use things, not love things and use people." - Unknown

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  Y Offline
                  Y Offline
                  york528
                  wrote on last edited by
                  #15

                  thank you i forgot to #define _WIN32_WINNT 0x400 the problem solved

                  1 Reply Last reply
                  0
                  • H Hamid Taebi

                    Can you show your code and it seems you forgot to include header file or your program?

                    Y Offline
                    Y Offline
                    york528
                    wrote on last edited by
                    #16

                    problem solved with #define _WIN32_WINNT 0x400 thank you for help me so much time and give me a lot usful advises

                    H 1 Reply Last reply
                    0
                    • A Ahmed Charfeddine

                      i expect that the threadFunction improperly tries to access the list object, etc which are own by the main thread. pass the this value to the param field of beginthread, then receive it inside your functionbloc and cast it to a main dialog pointer by wich you access things.

                      Our Philosophy, Mohammed Baqir Al Sadr

                      Y Offline
                      Y Offline
                      york528
                      wrote on last edited by
                      #17

                      problem solved with #define _WIN32_WINNT 0x400 thank you all

                      A 1 Reply Last reply
                      0
                      • Y york528

                        windows XP thank you so much #define _WIN32_WINNT 0x400 what's that for i am new and my English is not so good

                        E Offline
                        E Offline
                        Eytukan
                        wrote on last edited by
                        #18

                        Few APIs would be supported to specific OS. That's the OS version. Windows NT 4.0 -> _WIN32_WINNT =0x0400. The error is gone or not?


                        OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus Best wishes to Rexx[^]

                        Y 1 Reply Last reply
                        0
                        • E Eytukan

                          Few APIs would be supported to specific OS. That's the OS version. Windows NT 4.0 -> _WIN32_WINNT =0x0400. The error is gone or not?


                          OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus Best wishes to Rexx[^]

                          Y Offline
                          Y Offline
                          york528
                          wrote on last edited by
                          #19

                          it's already gone thank you ;P

                          E 1 Reply Last reply
                          0
                          • Y york528

                            it's already gone thank you ;P

                            E Offline
                            E Offline
                            Eytukan
                            wrote on last edited by
                            #20

                            Oh ok ok :beer:


                            OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus Best wishes to Rexx[^]

                            1 Reply Last reply
                            0
                            • S Saurabh Garg

                              Wow you have some serious issues!!!

                              hINTModuleState wrote:

                              CListCtrl m_list; // static UINT ThreadProc(LPVOID pParam) { CThreadQuestionDlg* pMe = reinterpret_cast(pParam); pMe->m_list.DeleteAllItems(); /*This is the case number 1*/ //m_list.DeleteAllItems(); /*This is the case number 2*/ return 0; } void StartThread() { AfxBeginThread(ThreadProc, this); }

                              Uncommenting second case will lead to compiling error because ThreadProc is a static function and a static function can only access static members of a class. Since m_list is not a static variable you cannot access it directly from with the function. For you profiling needs try http://www.codeproject.com/KB/datetime/perftimer.aspx[^] Saurabh

                              A Offline
                              A Offline
                              Ahmed Charfeddine
                              wrote on last edited by
                              #21

                              yes apparently i have serious issues. i'd better start find a book or pdf and learn all the keywords and langage basis before making any judgement on any thing. thank you for the profiler link.

                              Our Philosophy, Mohammed Baqir Al Sadr

                              1 Reply Last reply
                              0
                              • Y york528

                                problem solved with #define _WIN32_WINNT 0x400 thank you all

                                A Offline
                                A Offline
                                Ahmed Charfeddine
                                wrote on last edited by
                                #22

                                No comment.

                                Our Philosophy, Mohammed Baqir Al Sadr

                                1 Reply Last reply
                                0
                                • Y york528

                                  problem solved with #define _WIN32_WINNT 0x400 thank you for help me so much time and give me a lot usful advises

                                  H Offline
                                  H Offline
                                  Hamid Taebi
                                  wrote on last edited by
                                  #23

                                  It seems your problem solved and I arrived late,but I glad it solved. :-D

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups