win32 application with VS2008 not working on WIN-XP
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: win32 application with VS2008 not working on WIN-XP

  1. #1
    Join Date
    Apr 2013
    Posts
    77

    win32 application with VS2008 not working on WIN-XP

    I developed an application in win32 with VS2008 on WIN-7platform. this application is working as expected in WIN-7 but not working in WIN-XP. WIN-XP is not allowing my application to run completely, at some point abnormally terminating the application.Is there any technical reason for that? Or its my code problem?

    Regards,
    Manju

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,352

    Re: win32 application with VS2008 not working on WIN-XP

    Victor Nijegorodov

  3. #3
    Join Date
    Apr 1999
    Posts
    27,424

    Re: win32 application with VS2008 not working on WIN-XP

    Quote Originally Posted by manjut19 View Post
    I developed an application in win32 with VS2008 on WIN-7platform. this application is working as expected in WIN-7 but not working in WIN-XP. WIN-XP is not allowing my application to run completely, at some point abnormally terminating the application.Is there any technical reason for that?
    Let me add to what Victor posted:

    1) Your using C++ right? So any code that has any undefined behaviour is not guaranteed to run correctly. That is a given. If you're overrunning memory, using uninitialized variables, improper pointer manipulation, using illegal constructs such as returning a pointer or reference to a local variable, or any other aspect of C++ that happens to compile but is not guaranteed to work, then of course you're going to get weirdness and bugs. Even if it runs on every single Win-7 computer, it still is a bug. Remember that C++ does not protect you from these mistakes, unlike other computer languages.

    2) Do you check the return values from your function calls, or just assume they work? If you don't check your function return values and just assumes they returned "OK", then a Win-7 system may have returned "OK" from a function, while on Win-XP, the return value was "not OK", but you never checked it and the code goes down the "good" path when something is actually wrong. So make sure you are checking the return values for all your functions.

    Regards,

    Paul McKenzie

  4. #4
    Join Date
    Apr 2013
    Posts
    77

    Re: win32 application with VS2008 not working on WIN-XP

    Quote Originally Posted by Paul McKenzie View Post
    Let me add to what Victor posted:

    1) Your using C++ right? So any code that has any undefined behaviour is not guaranteed to run correctly. That is a given. If you're overrunning memory, using uninitialized variables, improper pointer manipulation, using illegal constructs such as returning a pointer or reference to a local variable, or any other aspect of C++ that happens to compile but is not guaranteed to work, then of course you're going to get weirdness and bugs. Even if it runs on every single Win-7 computer, it still is a bug. Remember that C++ does not protect you from these mistakes, unlike other computer languages.

    2) Do you check the return values from your function calls, or just assume they work? If you don't check your function return values and just assumes they returned "OK", then a Win-7 system may have returned "OK" from a function, while on Win-XP, the return value was "not OK", but you never checked it and the code goes down the "good" path when something is actually wrong. So make sure you are checking the return values for all your functions.

    Regards,

    Paul McKenzie
    You are correct sir, I was having a memory leaking problem I was allocating memory(Heap) for variable, But i was not Deallocating.Now that problem solved
    Code:
    TCHAR * pBuf=NULL;	//Using in another cpp file also
    HWND New_chld;
    #define IDC_CHILD_TEXT 101
    LRESULT CALLBACK TextBoxProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 
    { 
    switch (uMsg)
       {
       case WM_KEYDOWN:
    		{
    		switch (wParam) 
    			{
    				case VK_RETURN:				//Enter key Pressed
    				{
    					int iLen=GetWindowTextLength(GetDlgItem(New_chld,IDC_CHILD_TEXT));
    					if(iLen>0)
    					{
    						pBuf=(TCHAR *)GlobalAlloc(GPTR,iLen+1);
    						GetDlgItemText(New_chld,IDC_CHILD_TEXT,pBuf,iLen+1);
    						//Doing Some operation with pBuf value, in another cpp file
    						if(pBuf!=NULL)
    							GlobalFree(pBuf);
    					}
    				}
    				break;
    			}
    		}
    		break;
       }
    }
    This is the new code, Added GlobalFree,But Now if iam Debugging, When Control Reaches to GlobalFree,It is showing Corruption of the heap,What may be the problem

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,352

    Re: win32 application with VS2008 not working on WIN-XP

    Quote Originally Posted by manjut19 View Post
    Code:
    TCHAR * pBuf=NULL;	//Using in another cpp file also
    HWND New_chld;
    #define IDC_CHILD_TEXT 101
    LRESULT CALLBACK TextBoxProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 
    { 
    switch (uMsg)
       {
       case WM_KEYDOWN:
    		{
    		switch (wParam) 
    			{
    				case VK_RETURN:				//Enter key Pressed
    				{
    					int iLen=GetWindowTextLength(GetDlgItem(New_chld,IDC_CHILD_TEXT));
    					if(iLen>0)
    					{
    						pBuf=(TCHAR *)GlobalAlloc(GPTR, iLen+1);
    						GetDlgItemText(New_chld,IDC_CHILD_TEXT,pBuf,iLen+1);
    						//Doing Some operation with pBuf value, in another cpp file
    						if(pBuf!=NULL)
    							GlobalFree(pBuf);
    					}
    				}
    				break;
    			}
    		}
    		break;
       }
    }
    Is your build an ANSI or UNICODE?
    Note that GetWindowTextLength returns the length in characters while GlobalAlloc requires the buffer length to be in bytes (which value in the case of UNICODE is about twice bigger than the number of characters!)
    Victor Nijegorodov

  6. #6
    Join Date
    Apr 2013
    Posts
    77

    Re: win32 application with VS2008 not working on WIN-XP

    Quote Originally Posted by VictorN View Post
    Is your build an ANSI or UNICODE?
    Note that GetWindowTextLength returns the length in characters while GlobalAlloc requires the buffer length to be in bytes (which value in the case of UNICODE is about twice bigger than the number of characters!)
    build is UNICODE.So Can i Mdify to pBuf=(TCHAR *)GlobalAlloc(GPTR,sizeof(TCHAR));?

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,352

    Re: win32 application with VS2008 not working on WIN-XP

    Quote Originally Posted by manjut19 View Post
    build is UNICODE.So Can i Mdify to pBuf=(TCHAR *)GlobalAlloc(GPTR,sizeof(TCHAR));?
    Code:
    pBuf=(TCHAR*)GlobalAlloc(GPTR, (iLen+1) * sizeof(TCHAR));
    BTW, are you sure you do need GlobalAlloc / GlobalFree? Isn't new/delete not enough?
    Victor Nijegorodov

  8. #8
    Join Date
    Apr 2013
    Posts
    77

    Re: win32 application with VS2008 not working on WIN-XP

    Quote Originally Posted by VictorN View Post
    BTW, are you sure you do need GlobalAlloc / GlobalFree? Isn't new/delete not enough?
    Its no compalsary,I need a dynamic memory allocation thats all.Can you plaes tell me In which context,Global function or Heap function come into picture?

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,352

    Re: win32 application with VS2008 not working on WIN-XP

    GlobalAlloc function:
    Remarks
    Windows memory management does not provide a separate local heap and global heap. Therefore, the GlobalAlloc and LocalAlloc functions are essentially the same.
    The movable-memory flags GHND and GMEM_MOVABLE add unnecessary overhead and require locking to be used safely. They should be avoided unless documentation specifically states that they should be used.
    New applications should use the heap functions to allocate and manage memory unless the documentation specifically states that a global function should be used. For example, the global functions are still used with Dynamic Data Exchange (DDE), the clipboard functions, and OLE data objects.
    Standard C Library Functions
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center