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
Re: win32 application with VS2008 not working on WIN-XP
Re: win32 application with VS2008 not working on WIN-XP
Quote:
Originally Posted by
manjut19
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
Re: win32 application with VS2008 not working on WIN-XP
Quote:
Originally Posted by
Paul McKenzie
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
Re: win32 application with VS2008 not working on WIN-XP
Quote:
Originally Posted by
manjut19
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!)
Re: win32 application with VS2008 not working on WIN-XP
Quote:
Originally Posted by
VictorN
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));?
Re: win32 application with VS2008 not working on WIN-XP
Quote:
Originally Posted by
manjut19
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?
Re: win32 application with VS2008 not working on WIN-XP
Quote:
Originally Posted by
VictorN
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?
Re: win32 application with VS2008 not working on WIN-XP
GlobalAlloc function:
Quote:
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