|
WHy is this happening?
I have:
CImage & ImageRemus = m_PaletteMap[m_PalRemus];
If I put a breakpoint at this line and step in ,it crashes if I try to advance to next line of code (step over).
But if I put a breakpoint in the destructor of my CImage class, and say run to next breakpoint from this first breakpoint, it steps into the destructor!!!! (It crashes there).
Question is why is it stepping into the destructor?
Appreciate your help,
ns
|
|
|
|
|
There is not enough information, so I am going to guess.
1. member at position m_PalRemus does not exist.
2. CImage default constructor does not initialize object properly OR you did not overwrite copy constructor.
Could you show the whole function and exact declaration of the map. The declaration of CImage would help too.
|
|
|
|
|
Hi Alex,
I stil dont know why it went into the destructor. But I found out that I hadnt initialized a member in the constructor, so it was pointing to some invalid address. Then in the destructor I was having it delete that pointer if it existed. It did exist because it wasnt initialized and then it tried to delete it. The big mystery is --- why did it even go into the destructor in the first place? After i fixed the error (omission), and put breakpoints in the destructor, the program never did venture into the destructor .....puzzled.
Appreciate your help,
ns
|
|
|
|
|
Here is simplified explanation
std::map<key, type=""> operator[]:
1. check if member at Key position exist (same as calling map::find(Key))
2. if does not exist create new value
a. Create temporary object of Type (call to Type::Type() constructor)
b. Copy the temporary obect to the position [Key](call to Type::Type(const Type &) constructor)
c. Destroy temporary obect(call to Type::~Type())
3. Return Type& to the element at Key position
|
|
|
|
|
Thats really clarified the process to me. Thank you so much....now it makes perfect sense!!
Appreciate your help,
ns
|
|
|
|
|
the definition of std::map<>::operator[] says it returns value of insert(value_type(key, T())) .
this value_type(key, T()) creates temporary T object (CImage in your case) using default constructor. This temp object is destroyed when operator[] exits, therefore the destructor is called.
|
|
|
|
|
Thanks. I get it now...
Appreciate your help,
ns
|
|
|
|
|
here is my problem:
<br />
<br />
Class test<br />
<br />
void test::showmsg<br />
{<br />
AfxMessageBox(m_msg);<br />
}<br />
<br />
function thread<br />
<br />
UINT testThread(LPVOID param)<br />
{<br />
?????? ctrl = class mainclass control ??????<br />
<br />
for (int i = 0; i < 100; i++)<br />
{<br />
ctrl->m_msg.Format("%d", i);<br />
ctrl->showmsg();<br />
}<br />
<br />
return 0;<br />
}<br />
<br />
this is a simple example of what i want to do, the thread is gonna be a connection with a network.
|
|
|
|
|
When launching the thread, give this as parameter.
Then with a CMainDlg *ctrl = (CMainDlg*)param; (instead of the line where you put ?????)everything should be fine.
~RaGE();
|
|
|
|
|
You should pass a pointer to your class test when calling AfxBeginThread, supplying the pointer as second parameter.
in test, where starting your thread:
AfxBeginThread(testThread, (LPVOID)this)
|
|
|
|
|
How can we insert a gif file (or any image file ) in a dialog window ?
|
|
|
|
|
If it is a bmp, you have lots of possibility (Creating a CStatic, and load your bitmap in it with help of LoadBitmap() );
For gif or other, you'll have to get a specific loader.
~RaGE();
|
|
|
|
|
App runs fine when just executed. IF i put in a breakpoint and step in:
It crashes at the point where I create a map:
CImage x;
MyMap["abc"] = x;
(alternatively I did
CImage &x = MyMap["abc"]; - same effect )
The debug window says: Invalid Address specified to RtlFreeHeap
Looked it up on the web...not much help.
The assembly is pointing to an int 3 instruction
The call stack is in NTDLL.
Its in delete() in AFXMEM.cpp ( I think thats the name of the file where the call stack points to...)
Appreciate your help,
ns
|
|
|
|
|
seems that something tries to free (delete, delete[], free(), etc) a memory block which is not valid or already freed.
You might have a stack corruption, or your map class tries to free the "abc" string. There are a lot of possible causes.
Holy Sh*t! I'm speechless. (hey, that's a first) Marc Clifton, The Lounge
|
|
|
|
|
Yup. I found that I hadnt initialized a pointer in the constructor, and then was trying to delete it instantly if it exists. Of course it existed with garbage (unintialized) in it....so it was unhappy. Many thanks for the remote - hit the nail on the head debugging....
Appreciate your help,
ns
|
|
|
|
|
hi. i am working on a Game,and ive got a little problem.
my problem is in the below code :
<br />
Canalyze_b * ab= new Canalyze_b();<br />
ab->Create(IDD_AB,this);<br />
ab->SetWindowPos(&CWnd::wndTop ,140, 140, 300, 300, SWP_SHOWWINDOW);<br />
ab->ModifyStyle( WS_POPUP ,WS_CHILD,0);<br />
ab->ShowWindow(SW_SHOW); <br />
ab->analyze(NULL);<br />
<br />
Game s;<br />
s.analyze();
the s.analyze() operation will take time about 10 or 15 seconds. and i have to show the results of caculation during the operation. for example in a Simple EditBox.
for example in analyze() i have :
<br />
void Game::analyze(){<br />
<br />
while (n<100) {<br />
----> Show results on a Simple EditBox on dialog<br />
----> Calculate the next Position<br />
}<br />
}
my problem is that during the operation nothing Shown in the EditBox
and when the Operation ends only the last Result Will Shown on the Dialog !!
i think it's coz the Calculation function will takeover Showing results on the edit box and don't let it to occure. So is there any Way to Show Without any problem !
thanxxx
Regards.
-=Ehsan-de-Burge=-
|
|
|
|
|
-=Ehsan-de-Burge=- wrote:
So is there any Way to Show Without any problem !
Sure! Create your own worker thread. Then call it with AfxBeginThread(YourThread, YourParam). For easy calling functions of your dialog pass a pointer to your dialog as YourParam (think it should look like
UINT YourThread( LPVOID pParam );
...
AfxBeginThread(YourThread, (LPVOID )ab)
).
Now you can call any function on your dialog in your thread
UINT YourThread( LPVOID pParam ){
Canalyze_b * ab= (Canalyze_b *)pParam;
ab->DoAnything()
}
That's it!
|
|
|
|
|
hello
i have already submit this question.(thx again Schlaubi for your answer but i just know WM_PARENTNOTIFY works only for WM_LBUTTONDOWN and not for WM_LBUTTONUP.
i search something for IHTMLDocument2 but nothing.
So i can detect mouse butondown, but not mouse buttonup.
How can i detect all mouse click ?
|
|
|
|
|
Well, let's try something new;)
There is the possibility to establish a sink for all document events. This seems to be quiet easy when using ATL. But as you've access to MSDN for sure I'll won't go into detail. Search MSDN for DIID_HTMLDocumentEvents and you should find an appropriate example .
|
|
|
|
|
ok thx !
i try to find something about DIID_HTMLDocumentEvents on MSDN.
i hope to succeed !
|
|
|
|
|
jeremysay wrote:
i hope to succeed !
Hmmm ... seems like my good heart ever wins ...
that's an interesting site I found on MSDN:
HOWTO: Sink HTML Document Events for WebBrowser Host
Q246247
|
|
|
|
|
thx again
it seems complex but i try to understand
|
|
|
|
|
Anyone has/knows a good library for creating performance counters? The SDK way is pretty cumbersome, and I am not willing to write a WMI high-performance provider.
Hints? Links? Ideas?
Holy Sh*t! I'm speechless. (hey, that's a first) Marc Clifton, The Lounge
|
|
|
|
|
Boy are you in for some fun times! I just went through this myself and it is NOT very straightforward. I ended up borrowing some code from MSJ August 1998 and even then the integration was a huge pain. I don't have a link for you, but you can try to search for this:
Module name: PrfData.cpp
Notices: Written 1998 by Jeffrey Richter
Description: C++ template classes for Performance Object data types.
Good luck, you're gonna need it!
|
|
|
|
|
Erik Juhl wrote:
Boy are you in for some fun times
Yes, I've noticed already
Thanks for the hints.
Anyway, I've started a integration library, it might develop to a article on CodeProject. Looks promising.
Holy Sh*t! I'm speechless. (hey, that's a first) Marc Clifton, The Lounge
|
|
|
|