GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Feb-2005, 15:16
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough
Question

trouble with wm_gettext -- crashing and odd behavior


this is weird. my program, GeekEdit, after displaying a Save As... dialog box, displays a message box (for debugging purposes) with the text grabbed from the edit control, and then saves it into a file. (right now it doesn't actually save anything; all it does is open the file with CreateFile() and then close it with CloseHandle()). anyway, it isn't grabbing the text correctly, or something. if there is one character in the edit control, nothing displays in the message box. if there are two or more characters, the program crashes. huh?i would appreciate it if anyone can help me with this...

p.s. the attachment mechanism is broken (doesn't open a new window and therefore closes itself and leaves attachments in permanent "in progress" state) in firefox, so my source files are posted:
1. http://www.geocities.com/zapguyd/dow...ekedit.cpp.txt
2. http://www.geocities.com/zapguyd/dow...geekedit.h.txt
3. http://www.geocities.com/zapguyd/dow...eekedit.rc.txt
  #2  
Old 09-Feb-2005, 00:03
Dr. Evil Dr. Evil is offline
Member
 
Join Date: Oct 2004
Location: Netherlands
Posts: 120
Dr. Evil will become famous soon enough
You know, it's easier to call GetWindowTextLength() and GetWindowText() functions, I've never had any trouble with those. Another problem might be that you're using an int for the size, when it usually calls for a DWORD (unsigned long). I also don't see you allocating any memory, which might be somewhat problematic. In example:

CPP / C++ / C Code:
LPSTR text;
HWND edith;
DWORD len;

edith = GetDlgItem(winh, ID_MAIN_EDIT);
len = GetWindowTextLength(edith);

text = GlobalAlloc(GPTR, (len+1));
if(text != NULL)
{
   GetWindowText(edith, text, (len+1));
   
   //do whatever
   
   GlobalFree(text);
}
  #3  
Old 09-Feb-2005, 15:03
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough
thanx dr. evil, that works
although, the program compiled and ran without the GlobalAlloc() and GlobalFree() calls.
i omitted them because i didn't know what they did and had never used them before--what do they do and why are they necessary?
  #4  
Old 10-Feb-2005, 08:03
Dr. Evil Dr. Evil is offline
Member
 
Join Date: Oct 2004
Location: Netherlands
Posts: 120
Dr. Evil will become famous soon enough
Quote:
what do they do and why are they necessary?

They're basically the API versions of calloc() and free(), which would allocate memory to a pointer from the heap, otherwise you'd be trying to write/read memory which dosn't belong to you. However, I think C++ takes care of most of this for allocation and freeing for you, which would be why yours worked without those calls.
  #5  
Old 10-Feb-2005, 15:33
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough
thx, however...i have another, equally vexing, problem now
my program crashes on its call to WriteFile() to actually perform the save!

the files pointed to by the links in my first post have been updated

I get error code 0xc0000005, and I am assuming that means 5, which is ERROR_ACCESS_DENIED. So I am guessing (wild guess) that there is a problem with memory, or WriteFile() is trying to access part of tbw_text that isn't actually there (like going past the end of an array). argh. someone please help
  #6  
Old 10-Feb-2005, 18:04
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough
Angry

i forgot to add, if anyone cares, the error is reported as happening in the kernel32.dll module of my program, at address 0x000000007c810fb4

and i am running winxp sp2, compiled w/ dev-c++ 5 beta

also, i thought of another possibility for the error, if the file hadn't really been created. but i checked for that possibility, with the writefile() being inside an if(hFile)...
  #7  
Old 10-Feb-2005, 18:34
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough
YES! i fixed it
i found msdn's example, and played w/ the pointers so that it looked like what they had.
it turns out i do need those memory calls, stuff crashes without it
thanx 4 your help dr. evil
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:25.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.