GetWindowTextA() function not working in Visual Studio 2005?
-
Hi I am using Visual Studio 2005. I have developed my project in VC++ which is a dialog based MFC application. Here on the Button Click event of one dialog i need to get the value inserted in one edit box. for that I have declared variable also and i use GetWindowTextA() functions for that and it throw assertions. Showsing NULL value in hWnd... I don't know why this happens........any idea? The same code works fine in Visual Studio 6.0 My Code looks like this : ========================= void CPswdWnd::OnBnClickedButton1() { // TODO: Add your control notification handler code here char sCurPswd[512]=""; m_Pswd.GetWindowTextA(sCurPswd,strlen(sCurPswd)); //Here it give assertion } My Variables are declared by righ clicking the Editbox and then "Add Variables" and then i have made the variable as "Control". Any idea? Thankx in advance Mahesh
-
Hi I am using Visual Studio 2005. I have developed my project in VC++ which is a dialog based MFC application. Here on the Button Click event of one dialog i need to get the value inserted in one edit box. for that I have declared variable also and i use GetWindowTextA() functions for that and it throw assertions. Showsing NULL value in hWnd... I don't know why this happens........any idea? The same code works fine in Visual Studio 6.0 My Code looks like this : ========================= void CPswdWnd::OnBnClickedButton1() { // TODO: Add your control notification handler code here char sCurPswd[512]=""; m_Pswd.GetWindowTextA(sCurPswd,strlen(sCurPswd)); //Here it give assertion } My Variables are declared by righ clicking the Editbox and then "Add Variables" and then i have made the variable as "Control". Any idea? Thankx in advance Mahesh
void CPswdWnd::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
char sCurPswd[512]="";
m_Pswd.GetWindowText(sCurPswd,strlen(sCurPswd)); //Here it give assertion}
Without "A" at the end. The compiler decides then which one fits best. ~RaGE();
-
Hi I am using Visual Studio 2005. I have developed my project in VC++ which is a dialog based MFC application. Here on the Button Click event of one dialog i need to get the value inserted in one edit box. for that I have declared variable also and i use GetWindowTextA() functions for that and it throw assertions. Showsing NULL value in hWnd... I don't know why this happens........any idea? The same code works fine in Visual Studio 6.0 My Code looks like this : ========================= void CPswdWnd::OnBnClickedButton1() { // TODO: Add your control notification handler code here char sCurPswd[512]=""; m_Pswd.GetWindowTextA(sCurPswd,strlen(sCurPswd)); //Here it give assertion } My Variables are declared by righ clicking the Editbox and then "Add Variables" and then i have made the variable as "Control". Any idea? Thankx in advance Mahesh
It is likely ASSERTing because the you are passing the return from
strlen(...)
as the length of the buffer. These are two different things. You should be calling the function like:m_Pswd.GetWindowTextA(sCurPswd,512)
. Peace! --- Modified at 10:34 Tuesday 14th February, 2006 Actually, the second parameter is the max number of characters to copy into the buffer. This is important, because it does not mean the size of the buffer. That is why usingsizeof(...)
as was also suggested would be incorrect in a UNICODE build. -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!) -- modified at 10:34 Tuesday 14th February, 2006 Actually, the second parameter is the max number of characters to copy into the buffer. This is important, because it does not mean the size of the buffer. That is why usingsizeof(...)
as was also suggested would be incorrect in a UNICODE build. -
Hi I am using Visual Studio 2005. I have developed my project in VC++ which is a dialog based MFC application. Here on the Button Click event of one dialog i need to get the value inserted in one edit box. for that I have declared variable also and i use GetWindowTextA() functions for that and it throw assertions. Showsing NULL value in hWnd... I don't know why this happens........any idea? The same code works fine in Visual Studio 6.0 My Code looks like this : ========================= void CPswdWnd::OnBnClickedButton1() { // TODO: Add your control notification handler code here char sCurPswd[512]=""; m_Pswd.GetWindowTextA(sCurPswd,strlen(sCurPswd)); //Here it give assertion } My Variables are declared by righ clicking the Editbox and then "Add Variables" and then i have made the variable as "Control". Any idea? Thankx in advance Mahesh
Amarelia wrote:
m_Pswd.GetWindowTextA(sCurPswd,strlen(sCurPswd)); //Here it give assertion
Use
sizeof(sCurPswd)*sizeof(TCHAR)
instead ofstrlen(sCurPswd)
.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
-
void CPswdWnd::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
char sCurPswd[512]="";
m_Pswd.GetWindowText(sCurPswd,strlen(sCurPswd)); //Here it give assertion}
Without "A" at the end. The compiler decides then which one fits best. ~RaGE();
Since the buffer the O.P. allocated is a
char
buffer, they need to be using it with the ANSI version of the function. If their app is a UNICODE build,GetWindowText(...)
will resolve toGetWindowTextW(...)
, and will not accept thechar
buffer. Identifiers likeGetWindowText
that are#defined
to different functions (theA
orW
versions) depending on the build type should only be expected to work correctly under different build types when usingTCHAR
as the character type. Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!) -
Amarelia wrote:
m_Pswd.GetWindowTextA(sCurPswd,strlen(sCurPswd)); //Here it give assertion
Use
sizeof(sCurPswd)*sizeof(TCHAR)
instead ofstrlen(sCurPswd)
.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
DavidCrow wrote:
Use sizeof()*sizeof(TCHAR) instead of strlen().
Sorry you bug you Sir, Couldn't we use lstrlen for same?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
-
DavidCrow wrote:
Use sizeof()*sizeof(TCHAR) instead of strlen().
Sorry you bug you Sir, Couldn't we use lstrlen for same?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
ThatsAlok wrote:
Couldn't we use lstrlen for same?
Sure you can use it, but it'll still return 0 just like
strlen()
.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli