LNK2001 Error Using Edit Control Variable in static function
-
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.
-
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.
-
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.
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[^]
-
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[^]
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.
-
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.
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 thatstatic
word doing there?- Why do you call
UpdateData(FALSE);
in the middle of your updating process? If you look up theUpdateData()
function in MSDN, you see that this callsDoDataExchange()
which synchronizes the data of all the controls on your dialog. Knowing this, you should move the call toUpdataData(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[^]
- Why do you call
-
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 thatstatic
word doing there?- Why do you call
UpdateData(FALSE);
in the middle of your updating process? If you look up theUpdateData()
function in MSDN, you see that this callsDoDataExchange()
which synchronizes the data of all the controls on your dialog. Knowing this, you should move the call toUpdataData(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[^]
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.
- Why do you call
-
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 thatstatic
word doing there?- Why do you call
UpdateData(FALSE);
in the middle of your updating process? If you look up theUpdateData()
function in MSDN, you see that this callsDoDataExchange()
which synchronizes the data of all the controls on your dialog. Knowing this, you should move the call toUpdataData(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[^]
- Why do you call
-
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.
-
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
-
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.
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
-
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
-
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