|
ok, but how do you remove items from the list ? is it done automatically by the list class destructor ?
Watched code never compiles.
|
|
|
|
|
|
This may sound like a daft couple of questions...
- Are you sure the memory leak is in your class? Try swapping it for one that you know doesn't leak like std::list and run your analysis again.
- Why on earth are you writing your own linked list? std::list will probably do as good a job in most cases.
Ash
|
|
|
|
|
Aescleal wrote: - Why on earth are you writing your own linked list?
Academia.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi all,
I have a problem to set correctly the color background of a CTabCtrl under Windows XP. IT work great under Vista/Seven. But XP still not working after many try.
So you can see 2 print screen (one in Vista and one in XP) you will see that the one on XP don't paint correctly the background windows (right beside the last tab).
http://www.devntic.com/IMAGES/PrintSreenVista.jpg[^]
http://www.devntic.com/IMAGES/printscreenXP.JPG[^]
this is my code to do what you see in these print screen..
I have a Class to manage CTabCtrl --> in this case COnglet (it's Tab in french)
BOOL COnglet::OnEraseBkgnd(CDC* pDC)
{
RECT rect;
this->GetWindowRect(&rect);
::FillRect(pDC->GetSafeHdc(), &rect, static_cast<HBRUSH>(((CDlg_Modele*)m_TabOnglet[0]->ptrEcran)->m_DlgBGColor));
return FALSE;
}
void COnglet::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CRect rect = lpDrawItemStruct->rcItem;
rect.top += ::GetSystemMetrics(SM_CYEDGE);
....
...
pDC->SetBkMode(TRANSPARENT);
pDC->FillSolidRect(rect, ((CDlg_Modele*)m_TabOnglet[0]->ptrEcran)->m_bgColor);
...
...
pDC->RestoreDC(nSavedDC);
}
Thanks in advance for any help you could provide to me
regard Etienne
PS: sorry, my english is not perfect.
modified on Wednesday, July 21, 2010 3:18 PM
|
|
|
|
|
I gave the class an English sounding name, et voilà
BOOL CMyTabCtrl::OnEraseBkgnd(CDC* pDC)
{
RECT rect;
this->GetWindowRect(&rect);
ScreenToClient(&rect);
::FillRect(pDC->GetSafeHdc(), &rect, static_cast<HBRUSH>(((CDlg_Modele*)m_TabOnglet[0]->ptrEcran)->m_DlgBGColor));
return FALSE;
}
I strongly suggest that you give identifiers English names, unless a customer demands another language in a contract. And even then, try to convince him before accepting.
A simple thing as asking for help might reduce your chances of getting a good response. But there are better reasons, working with developers from different countries being one. Going public with parts of your code being another. I once had an interface file for a complex system completely in Dutch in my hands. Oh my oh my...
|
|
|
|
|
Was it Dutch, Dutch++ or maybe Dutch#?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
I'm glad you see the problem
|
|
|
|
|
Thanks for your reply and your advice.
I added the line of code that you suggested but it seems not to be working anyway in windows XP (Tested on Windows XP sp3).
To see whitch area i painted In OnEraseBkgnd, i changed the color and in Vista all seems to be in good place like you can see on this printscreen
http://www.devntic.com/IMAGES/VistaGreen.jpg[^]
but in XP i didn't see anything changing.
So what's wrong With XP and CTabCtrl?
Thanks again.
|
|
|
|
|
Hi,
Im having a LPSTR variable.I want to copy a string to this variable. The application is getting crashed while copying this string.I want to catch this exception.I have used exception class,but its not capturing that one.Please suggest me to do this.Im using the following code.
LPSTR lpszstr;
try
{
wsprintf(lpszstr,"%s","sdfsdfsd fsdfsdfsdf");
}
catch (CException *why)
{
::MessageBox(NULL,"test123","test",MB_OK);
}
Thanks,
|
|
|
|
|
People on these forums seem a bit obsessed by exceptions...
- wsprintf is a windows API function. Windows API function have a C interface, not a C++ one. As C compilers don't understand C++ exception handling Windows API functions don't throw C++ exceptions. Therefore whatever wsprintf does it won't throw, ever.
- CException is an MFC class. The only thing that throws exceptions based on CException is MFC and clients of MFC. Even if the previous point didn't apply then wsprintf couldn't throw a CException.
- IF wsprintf threw a CException derived class you're still using it wrong. MFC (due to it's long history of working on brain damaged compilers) throws exceptions by pointer and not by value. When you catch an MFC exception AND handle it you have to delete the exception afterwards. Not generally using the delete operator either. Have a look at the docs for details.
- finally even if wsprintf threw what you want it to catching it would be a bad idea. You've got code that's writing to a random area of memory. Do you really expect to be able to scribble over your process address space and get away with it? Sometimes you might be able to recover and keep going, hopefully most of the time your code will crash in a heap.
So:
- stop obsessing about exceptions but if you can't stop learn the difference between a processor exception, an operating system exception and a C++ exception
- stop mucking about with low level stuff. Don't use array of characters use vectors or strings. Don't think they're something advanced - it's the stuff you're doing (pointers and arrays and not knowing the differences between them, using C functions like sprintf when stringstreams do in a far safer manner) that's advanced
Ash
|
|
|
|
|
In addition to what Ash said, note that:
- LPSTR is a pointer to a multi-byte string (i.e.
char * ), but you are using wsprintf which is an unicode function (i.e. it works on wchar_t ) - when used with
wsprintf , the format string "%s" stand for an unicode string, but you are passing a multi-byte string instead: probably this is the reason of the crashes you are experiencing. Replace wsprintf with sprintf - to avoid problems with buffer overrun improved versions of
sprintf and wsprintf are privided: think using printf_s and wsprintf_s
|
|
|
|
|
Hi Sauro,
wsprintf (which resolves into wsprintfA and wsprintfW) is a version of either sprintf or swprintf implemented by USER (IIRC, might be KERNEL). swprintf is the unicode sprintf like function - nice of them to change a couple of letters like that!
To add to the confusion wsprintf can't handle any floating point formats the way sprintf and swprintf can and can only handle 1k of characters.
Cheers,
Ash
|
|
|
|
|
Sauro Viti wrote: wsprintf which is an unicode function
1. Not true, it works on either and is actually defined to wsprintfA or wsprintfW depending on the setting of UNICODE .
2. see 1, but also the reason for the crash is that lpszstr is not initialised to point to anything.
3. wsprintf_s does not exist. As far as I recall the wxxx functions were created for windows programs that did not include stdio.h .
It's time for a new signature.
|
|
|
|
|
LPSTR lpszstr;
this is a pointer, not a string. and it doesn't point anywhere (you haven't initialized it). you need to allocate some memory for a string, and then use that in your wsprintf.
you need something like this:
TCHAR str[100];
wsprintf(str,"%s","sdfsdfsd fsdfsdfsdf");
also, it might be good to read about the differences between pointers and arrays[^].
|
|
|
|
|
if you didn't allocate enough memory for lpszstr to hold the string you copy to it, definitly access violation will happen, and as wsprintf() doesn't throw any exception, you can't expect to catch it
|
|
|
|
|
最近在写个驱动安装程序,里面用到一些内核函数比如UpdateDriverforPlugAndDevice(),用的vs2008,在32位操作系统下工作正常,win32的程序可以在x64下运行,但是在64位下就会出错,比如UpdateDriverforPlugAndDevice(),我用GetLastError(),看到出错。后来我在64位系统下装了vs2008,编译出x64程序,一切运行正常,但是这个程序无法在win32下运行。问题是解决了,但是我现在用维护两个版本32下一个,64位一个;不知道大家有什么好方法,只要运行一个版本。
|
|
|
|
|
Sorry, but we cannot understand this, can you please have your question translated into English?
It's time for a new signature.
|
|
|
|
|
This is an english only website, please translate your question: we are not able to understand it
|
|
|
|
|
|
xjh_sz wrote: For example UpdateDriverforPlugAndDevice (), I used GetLastError (), see the error.
And what is that error?
xjh_sz wrote: The problem is solved, but I now maintain two versions with the next 32, 64 a; do not know what a good way, just run a version. Not sure I understand this. Are you wanting one set of source code, but two separate exe files?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Dave,
It is nice of you to translate OP question and try to give some clue. Shouldn't you tranlated your answer to chinease though
|
|
|
|
|
Yusuf wrote: Shouldn't you tranlated your answer to chinease though
不,我不会说中文。
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
You would get more help if you describe your problems in English.
以前你也用中文在这里叫过吧?鬼佬们不懂中文,白瞎了~~
个人理解,仅供参考:
win32程序在win64上面是通过wow64工作的,被。64位程隔离在一个独立的环境里面序和32位程序在用户层不可互访。因此没有办法只用一个程序在64位和32位间无缝转换。即64环境中必须用64的程序才能安装64位的驱动,32位环境中只能用32位程序安装驱动。
不过完全可以做到在源代码层面统一。
modified on Wednesday, July 21, 2010 9:19 AM
|
|
|
|
|
xjh_sz wrote:
I recently created a driver installation program, which uses a number of core functions such as UpdateDriverforPlugAndDevices(), using vs2008, in 32-bit operating system everything is working properly. But win32 program can run in x64, but under x64 it does not work. For example UpdateDriverForPlugandPlayDevices() raises an error, I used GetLastError (), and I see an error code. Later I was using a 64-bit system with vs2008 and compiled the x64 program, everything works fine, but the program can not run in win32. The problem is now solved, but I now maintain two versions of the installer 32 and 64; I do not know what a better way, I just run a seperate version of the executable.
Hi xjh_sz,
I believe that you are doing the correct thing by creating two separate installers for 32 and 64 bit. UpdateDriverForPlugAndPlayDevices does not support WOW64. You might be able to get your 32 bit installer to work by calling Wow64EnableWow64FsRedirection[^] but I honestly don't know for sure.
Some additional documentation:
Driver Installation for 32-bit and 64-bit Platforms[^]
Best Wishes,
-David Delaune
|
|
|
|