Click here to Skip to main content
15,308,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have CString variables declared as public in my class, yet when I try to set a maximum length "m_string1.SetLength(9)" I get a compile error "cannot access private member declared in class 'ATL::CSimpleStringT<BaseType,t_bMFCDLL>::SetLength'.

This is being used in an edit control box.

Beginner here with no concept of what's going on with ATL???

Any help appreciated...



I want to limit the user to 8 characters of input to an edit control box...
I thought there would be a MAXLENTH in the options where I created the edit boxes, but nothing there.
Guess I need to change from CString to char[9]?

How do I find CString's ("its base class") or any other base class? I have no idea, these are the simple things I'm missing.
Updated 1-Jun-11 5:57am
Alain Rist 1-Jun-11 12:05pm
The edit control text length has nothing to do with CString. See my edited answer.

Hi Scott,
There is no concept of a maximum length for CString, the length depends on the content.
If you wish to set the allocated size to avoid copying use void CString::Preallocate(int length).

Edit after question update:

If you want to limit the length of accepted text for an Edit Control send it the EM_SETLIMITTEXT message:
::SendMessage(hWndofMyControl, EM_SETLIMITTEXT, 8, 0); // limit to 8 characters accepted
sbwilliams59 1-Jun-11 13:58pm
Thanks Alain...that was exactly what I needed...learned how to get a handle in the process (GetDlgItem(m_string)->mWnd).

Albert Holguin 1-Jun-11 15:44pm
GetDlgItem(m_string) makes no sense btw...
Albert Holguin 1-Jun-11 15:45pm
When you call GetDlgItem(ID) you pass a resource ID of the control you want to get a handle to.
sbwilliams59 1-Jun-11 13:59pm
make that ->m_hWnd
Not sure why you're trying to set the length of a CString yourself directly... ???

CStrings are dynamic, meaning they'll allocate any memory themselves based on what data you want them to hold. What are you really trying to do by setting the length of that string?

By the way, SetLength is not a member of CString, its a member of its base class, which is why you get the error. Meaning under regular conditions, you shouldn't need to access that member. Are you trying to Truncate()?
sbwilliams59 1-Jun-11 14:06pm
I could have posed the question better...thanks for the input.
Albert Holguin 1-Jun-11 15:44pm
I see what you were trying to achieve now, yep, that has nothing to do with CString
sbwilliams59 1-Jun-11 16:11pm
and m_string was what I had tied to the control, not the actual control IDC_yada...again, I misspoke.
Albert Holguin 1-Jun-11 16:26pm
lol, ok... as long as you're learning as you go...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900