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. LNK2001 Error Using Edit Control Variable in static function

LNK2001 Error Using Edit Control Variable in static function

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpjsontutorial
12 Posts 4 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.
  • C Offline
    C Offline
    CNewbie
    wrote on last edited by
    #1

    I searched for my problem and found other who had it, but didn't find an answer. I am getting "LNK2001: unresolved External Symbol" in my MFC Dialog Box Program. Here is my situation: The unresolved symbol is a CString that belongs to my Edit Control. It is declared as a Public variable in my main dialog class in "dialog1.h". Now this is being used within a static member function (in the same class) which is declared in "dialog1.h" (The function is a Seperate Thread being called by AfxBeginThread() from "dialog1.cpp". The actually Function however is in "dialog2.cpp". The CString is being used within this function in "dialog2.cpp". Both "dialog1.cpp" and "dialog2.cpp" have includes for "dialog1.h", so I do not see the reason why this is happening. I thought of making this CString external, but I am not sure how to do it when it is a member of a class. Rundown: CString Variable: Declared in dialog1.h and initialized in dialog2.cpp static member function: declared in dialog1.h and initialized in dialog2.cpp Static member function is called from dialog1.cpp using AfxBeginThread() API. If anyone has any suggesstions that would be great.

    G B 2 Replies Last reply
    0
    • C CNewbie

      I searched for my problem and found other who had it, but didn't find an answer. I am getting "LNK2001: unresolved External Symbol" in my MFC Dialog Box Program. Here is my situation: The unresolved symbol is a CString that belongs to my Edit Control. It is declared as a Public variable in my main dialog class in "dialog1.h". Now this is being used within a static member function (in the same class) which is declared in "dialog1.h" (The function is a Seperate Thread being called by AfxBeginThread() from "dialog1.cpp". The actually Function however is in "dialog2.cpp". The CString is being used within this function in "dialog2.cpp". Both "dialog1.cpp" and "dialog2.cpp" have includes for "dialog1.h", so I do not see the reason why this is happening. I thought of making this CString external, but I am not sure how to do it when it is a member of a class. Rundown: CString Variable: Declared in dialog1.h and initialized in dialog2.cpp static member function: declared in dialog1.h and initialized in dialog2.cpp Static member function is called from dialog1.cpp using AfxBeginThread() API. If anyone has any suggesstions that would be great.

      G Offline
      G Offline
      GDavy
      wrote on last edited by
      #2

      you can not access non-static members of a class within a static function. you can only access that member through an instance of the class passed as a parameter for example. Greetings, Davy

      1 Reply Last reply
      0
      • C CNewbie

        I searched for my problem and found other who had it, but didn't find an answer. I am getting "LNK2001: unresolved External Symbol" in my MFC Dialog Box Program. Here is my situation: The unresolved symbol is a CString that belongs to my Edit Control. It is declared as a Public variable in my main dialog class in "dialog1.h". Now this is being used within a static member function (in the same class) which is declared in "dialog1.h" (The function is a Seperate Thread being called by AfxBeginThread() from "dialog1.cpp". The actually Function however is in "dialog2.cpp". The CString is being used within this function in "dialog2.cpp". Both "dialog1.cpp" and "dialog2.cpp" have includes for "dialog1.h", so I do not see the reason why this is happening. I thought of making this CString external, but I am not sure how to do it when it is a member of a class. Rundown: CString Variable: Declared in dialog1.h and initialized in dialog2.cpp static member function: declared in dialog1.h and initialized in dialog2.cpp Static member function is called from dialog1.cpp using AfxBeginThread() API. If anyone has any suggesstions that would be great.

        B Offline
        B Offline
        Bob Stanneveld
        wrote on last edited by
        #3

        So if I understand correctly, you have a static CString member variable in your edit control, which is the unresolved external symbol right? If this is the case, your code of your edit control should look like this:

        class CMyEditCtrl : public CEdit
        {
        public:
        // some stuff
        static CString st_sSomeString;
        // other stuff
        };

        if this is the case, your problem is that you didn't declare the static variable. In MyEditCtrl.cpp, add the declaration like this:

        CString CMyEditCtrl::st_sSomeString = "";

        That should resolve your problem. If the above is not your case, try to clearify your problem, by posting some code snippets.. Hope this helps :) Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

        C 1 Reply Last reply
        0
        • B Bob Stanneveld

          So if I understand correctly, you have a static CString member variable in your edit control, which is the unresolved external symbol right? If this is the case, your code of your edit control should look like this:

          class CMyEditCtrl : public CEdit
          {
          public:
          // some stuff
          static CString st_sSomeString;
          // other stuff
          };

          if this is the case, your problem is that you didn't declare the static variable. In MyEditCtrl.cpp, add the declaration like this:

          CString CMyEditCtrl::st_sSomeString = "";

          That should resolve your problem. If the above is not your case, try to clearify your problem, by posting some code snippets.. Hope this helps :) Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

          C Offline
          C Offline
          CNewbie
          wrote on last edited by
          #4

          Thank You Bob, This did solve my problem :) However, now I am not getting output to my edit box. Here is what I am doing: static CString mystring; CProgressCtrl m_sigstr; UINT getstring[4]; m_string.Format("%d",getstring[1]); // Format m_string with a decimal Number static UpdateData(FALSE); // Send New string to Edit Box m_sigstr.SetPos( getstring[1] ); // Set Position of Progress Bar according to getstring value getstring [1] both holds the value I want to output to the edit box and use to reposition the progress bar. From a debug I did, it is not working on the progress bar as well as not outputting the value to the Edit Box.

          B D 2 Replies Last reply
          0
          • C CNewbie

            Thank You Bob, This did solve my problem :) However, now I am not getting output to my edit box. Here is what I am doing: static CString mystring; CProgressCtrl m_sigstr; UINT getstring[4]; m_string.Format("%d",getstring[1]); // Format m_string with a decimal Number static UpdateData(FALSE); // Send New string to Edit Box m_sigstr.SetPos( getstring[1] ); // Set Position of Progress Bar according to getstring value getstring [1] both holds the value I want to output to the edit box and use to reposition the progress bar. From a debug I did, it is not working on the progress bar as well as not outputting the value to the Edit Box.

            B Offline
            B Offline
            Bob Stanneveld
            wrote on last edited by
            #5

            CNewbie wrote: m_string.Format("%d",getstring[1]); // Format m_string with a decimal Number static UpdateData(FALSE); // Send New string to Edit Box m_sigstr.SetPos( getstring[1] ); // Set Position of Progress Bar according to getstring value Consider that code fragment. I thought about the following things the moment I say it:* What is that static word doing there?

            • Why do you call UpdateData(FALSE); in the middle of your updating process? If you look up the UpdateData() function in MSDN, you see that this calls DoDataExchange() which synchronizes the data of all the controls on your dialog. Knowing this, you should move the call to UpdataData(FALSE) down the bottom of the function. After this, all the changes will be made visible. Hope this helps :-D Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]
            C 2 Replies Last reply
            0
            • B Bob Stanneveld

              CNewbie wrote: m_string.Format("%d",getstring[1]); // Format m_string with a decimal Number static UpdateData(FALSE); // Send New string to Edit Box m_sigstr.SetPos( getstring[1] ); // Set Position of Progress Bar according to getstring value Consider that code fragment. I thought about the following things the moment I say it:* What is that static word doing there?

              • Why do you call UpdateData(FALSE); in the middle of your updating process? If you look up the UpdateData() function in MSDN, you see that this calls DoDataExchange() which synchronizes the data of all the controls on your dialog. Knowing this, you should move the call to UpdataData(FALSE) down the bottom of the function. After this, all the changes will be made visible. Hope this helps :-D Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]
              C Offline
              C Offline
              CNewbie
              wrote on last edited by
              #6

              Thanks for responding. I understand your logic, but the reason why I cannot do that is because that function loops over and over again every 500ms until a condition is met and then it exits. The Edit control as well as the progress bar will update at the bottom of every iteration. So you see if I put the UpdateData() at the end of the function, the edit box would never update until the function exited and that would defeat the whole purpose of what I want to do here.

              B 1 Reply Last reply
              0
              • B Bob Stanneveld

                CNewbie wrote: m_string.Format("%d",getstring[1]); // Format m_string with a decimal Number static UpdateData(FALSE); // Send New string to Edit Box m_sigstr.SetPos( getstring[1] ); // Set Position of Progress Bar according to getstring value Consider that code fragment. I thought about the following things the moment I say it:* What is that static word doing there?

                • Why do you call UpdateData(FALSE); in the middle of your updating process? If you look up the UpdateData() function in MSDN, you see that this calls DoDataExchange() which synchronizes the data of all the controls on your dialog. Knowing this, you should move the call to UpdataData(FALSE) down the bottom of the function. After this, all the changes will be made visible. Hope this helps :-D Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]
                C Offline
                C Offline
                CNewbie
                wrote on last edited by
                #7

                Also If I dont put "static" in front of UpdateData(FALSE), I get this error: error C2352: 'CWnd::UpdateData' : illegal call of non-static member function

                B 1 Reply Last reply
                0
                • C CNewbie

                  Thanks for responding. I understand your logic, but the reason why I cannot do that is because that function loops over and over again every 500ms until a condition is met and then it exits. The Edit control as well as the progress bar will update at the bottom of every iteration. So you see if I put the UpdateData() at the end of the function, the edit box would never update until the function exited and that would defeat the whole purpose of what I want to do here.

                  B Offline
                  B Offline
                  Bob Stanneveld
                  wrote on last edited by
                  #8

                  Than put the call to UpdateData() after you update the progress bar instead of before it... Sometimes, a little bit of experimenting will do magic for you... Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                  1 Reply Last reply
                  0
                  • C CNewbie

                    Also If I dont put "static" in front of UpdateData(FALSE), I get this error: error C2352: 'CWnd::UpdateData' : illegal call of non-static member function

                    B Offline
                    B Offline
                    Bob Stanneveld
                    wrote on last edited by
                    #9

                    I've never seen that before... It doesn't seem like legal C++ to me, but if the compiler accepts it, I must be wrong... Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                    1 Reply Last reply
                    0
                    • C CNewbie

                      Thank You Bob, This did solve my problem :) However, now I am not getting output to my edit box. Here is what I am doing: static CString mystring; CProgressCtrl m_sigstr; UINT getstring[4]; m_string.Format("%d",getstring[1]); // Format m_string with a decimal Number static UpdateData(FALSE); // Send New string to Edit Box m_sigstr.SetPos( getstring[1] ); // Set Position of Progress Bar according to getstring value getstring [1] both holds the value I want to output to the edit box and use to reposition the progress bar. From a debug I did, it is not working on the progress bar as well as not outputting the value to the Edit Box.

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      Are you attempting to update a control on the dialog from another thread? If so, this is extremely dangerous and not recommended.


                      "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                      C 1 Reply Last reply
                      0
                      • D David Crow

                        Are you attempting to update a control on the dialog from another thread? If so, this is extremely dangerous and not recommended.


                        "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                        C Offline
                        C Offline
                        CNewbie
                        wrote on last edited by
                        #11

                        Thank you for the reply David. Do you have any recommendations on how I can go about outputting to the window from within this thread. Basically i want to do the math and output every 500ms. Thanks

                        D 1 Reply Last reply
                        0
                        • C CNewbie

                          Thank you for the reply David. Do you have any recommendations on how I can go about outputting to the window from within this thread. Basically i want to do the math and output every 500ms. Thanks

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #12

                          CNewbie wrote: Do you have any recommendations on how I can go about outputting to the window from within this thread. Yes, post a message back to the main thread who is in charge of the UI. See here and here.


                          "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                          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