hello guys...if it is simple question plz excuse me...
1) I have a var associated with ListBox (you know adding var to the control in MFC). Now I can access it in one class "MyProgDlg.cpp" but can't access it in another class "classA.cpp", why is this so

2) how do I concatinate a DWORD with CSTRING var inorder to add it to ListBox??
Here is the code from classA.cpp...

CString str = "Line#";
LPSTR str1 = str.GetBuffer(str.GetLength());
strcat(str1,DevIndex);
SetDlgItemText(IDC_LIST,str1);

1) Maybe because the class does *not* include the header of the ListBox item.
2) Try this:

DWORD dw = 100;
str += dw;

@nbaztec: The += operator does not work with integers.

1) ListBox is most likely a private member of MyProgDlg.cpp and is therefore unaccessible outside that class.

2) CString class has a Format() method whose parameters are identiacal to sprintf()

CString str;
DWORD dbIndex = 123;
str.Format("Line# %u", devIndex);

@AD
Thanks for pointing, I guessed since CString looked fairly similar to String, WideString etc. & all of them had overload += operators, so must it.

CString does have overloaded += operators, but none of them take an integer.

1) ListBox is most likely a private member of MyProgDlg.cpp and is therefore unaccessible outside that class.

@Ancient Dragon
I have just dragges the control onto the form and added variable to it, I dont know how can the member access spedifier be private or public?? and plz let me know how can I change it??

look at the header file and you will see whether its public or private. Don't be afraid to browse around the header files in the project and become familiar with what they contain.

>> plz let me know how can I change it??
You don't want to change it. Instead, write a public method that allows other classes access to the ListBox. For example, if ClassA wants to add a string to the list box, then in MyProgDlg.cpp you would write a public method that accepts a string as parameter and then it adds the string to the list box. This is exactly the same technique used in all c++ programs called getters and setters

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.