|
As John says create a kill event, you won't just get memory leaks, but you could get an exception as well!
Just raise a kill event and use WaitForSingleObject on the thread handle with, say a 5 second timeout, only a very last resort use TerminateThread()
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
Theres a CP project :
http://www.codeproject.com/docking/ToolbarWithCombo.asp
which has either a regular combobox being created in the toolbar or a CSmartComboBox (derived from CComboBox).
However
BOOL CreateComboBox(class CComboBox& comboBox, UINT nIndex, UINT nID, int nWidth, int nDropHeight);
has class CComboBox in it. Can I pass in a SmartComboBox variable instead? Or do I have to modify the function to:
BOOL CreateComboBox(class CSmartComboBox& comboBox, UINT nIndex, UINT nID, int nWidth, int nDropHeight);
?
The second question is : why the word class in class CComboBox& comboBox ??? Cant it just be:
CreateComboBox(CComboBox& comboBox,...) withgout the word class?
Appreciate your help,
ns
|
|
|
|
|
ns wrote:
...has class CComboBox in it. Can I pass in a SmartComboBox variable instead?
Yes, so long as SmartComboBox is derived from CComboBox.
ns wrote:
Cant it just be:
CreateComboBox(CComboBox& comboBox,...) withgout the word class?
Yes.
cheers,
-B
|
|
|
|
|
MAny thanks! That helps!
Appreciate your help,
ns
|
|
|
|
|
Got a quick question the following code works in the OnInitDialog function of CPropertySheet, however the same code does nothing in the OnInitDialog function of the CPropertyPage?
// CPropertySheet OnInitDialog code
CRect rect;
CPropertyPage *pPage = GetActivePage();
pPage->GetWindowRect(&rect);
ScreenToClient(&rect);
rect.right += 50;
rect.bottom += 50;
pPage->MoveWindow(&rect);
// CPropertyPage OnInitDialog code
CRect rect;
GetWindowRect(&rect);
ScreenToClient(&rect);
rect.right += 50;
rect.bottom += 50;
MoveWindow(&rect);
Now i know it shouldn't matter to me cause i got it working in the sheet, but it's driving me crazy knowing that this should work in each individual page as well!! Help me understand this craziness
|
|
|
|
|
WHy do they have tbbs_separator in the following in the CP article:
SetButtonInfo (0, ID_EDIT_R, <code>TBBS_SEPARATOR </code>, <code>cxChar * 8</code>);
GetItemRect (0, &rect);
http://www.codeproject.com/docking/spnsld.asp
FRom MSDN:
void SetButtonInfo(
int nIndex,
UINT nID,
UINT nStyle,
int <code>iImage </code>);
THe fourth parameter is puzzling me too.....they are two different things...cxChar * 8
looks like a width, not an image index....
Appreciate your help,
ns
|
|
|
|
|
ns wrote:
cxChar * 8
is the width of the separator
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
TBBS_SEPARATOR indicates the use of an separator. Then it's size is widened to have place for inserting other elements. This is the common method for placing custom items like combo boxes etc. on a toolbar.
|
|
|
|
|
Ah! Thank you for clearing that!!!! I was really puzzled on this one!!
Appreciate your help,
ns
|
|
|
|
|
The release exe runs fine. The debug one crashes on:
CBKDoc * pDoc = (CBKDoc *)GetDocument();
pDoc->dynaMenuMap.clear();
where:
typedef std::set <CString> SubMenuSet;
typedef std::map <CString, SubMenuSet> DynaMenuMap;
;
THe very first time I entere the function, DynaMenuMap dynaMenuMap is empty, so perhaps clearing an empty map is a no-no? The release exe doesnt care....
How do I sidestep this?
Appreciate your help,
ns
|
|
|
|
|
int size = pDoc->dynaMenuMap.size();
if (pDoc->dynaMenuMap.size())
{
pDoc->dynaMenuMap.clear();
}
THe map starts out empty, and I clear only if its not empty....but now my debug version is saying size = some large neg number. All I have in the code mentioning the map untilk this point is DynaMenuMap dynaMenuMap in the .h file...
Appreciate your help,
ns
|
|
|
|
|
Are you certain it's crashing on the clear() call?
(It may be the case that pDoc is NULL, though I don't see why that would work in release but not in debug)
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
pDoc is not null . The size of the empty map is weird: some larege neg number. If I get rid of the clear(), it still crashes , but on the line in red!!!!!! If I put the clear(0 in it crashes on the clear()!!!!!!!!!!!
int size = pDoc->dynaMenuMap.size();
if (pDoc->dynaMenuMap.size())
{
pDoc->dynaMenuMap.clear();
}
<code>SubMenuSet & subMenuCat = pDoc->dynaMenuMap["Cat</code>"];
//crashes here if I comment out the clear()
size = -125......
Appreciate your help,
ns
|
|
|
|
|
ns wrote:
The size of the empty map is weird: some larege neg number
No;P Its just unsigned int .
You can use dynaMenuMap::size_type as type for your size results, but in the current implementation, this is just typedef ed to unsigned int .
Personally, I use size_t , AFAIK defined by Microsoft to be unsigned int .
Less typing as 'unsigned int ', and conveyes a meaning.
<edit> Something must be rotten with your doc-pointer.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
I guess its the pointer...but what can I do?
In a view class where I generate the map:
unsigned int size = pDoc->dynaMenuMap.size();
with unsigned, I still get a non zero number --- large positive!!! Theres been no map created so far!!! So it should be zero!
But in the doc class whose member the map is:
BOOL CBKDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
CString abc;
abc.Format(" size of map in doc is %d", dynaMenuMap.size());
AfxMessageBox(abc);
return TRUE;
} retiurns size of zero!!! As it should...
Appreciate your help,
ns
|
|
|
|
|
Hi ns, most likely pDoc is not a valid pointer: check if other members of this object hold consistent values.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
What he said...
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Pardon me? I don't get what you mean.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Whoops, I guess that is a colloquialism.
I basically said I agree with you on all counts.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
OK Excuse my poor understanding, I'm not a native English speaker and I guess it shows.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
This is really really upsetting!! I went and put in a member int testing variable in the doc (like you suggested) , and retrieved it in the offending view with the pDoc->. That came out fine! The next line was my size(). Now this came out 0!!!! Like it should be. Then the program ran perfectly in debug. SO I went and undid the addition of the int test variable in doc, and viola!!!! it still works perfectly. I am really puzzled and mistrustful now.....it bothers me when things get fixed miraculously...........
I am nonplussed!
Appreciate your help,
ns
|
|
|
|
|
You'd be better of testing it with the empty() function instead of size()
~RaGE();
|
|
|
|
|
I'm betting this is due to the cast on the document pointer. Didn't you add that GetDocument member I told you about? On a more serious note, you shouldn't have to cast that document pointer. I spent 2 weeks debugging a similar problem a couple years ago, where the compiler wasn't generating the correct address for the pointer because I was doing a "C" style cast. This would explain your "garbage" number, and (partially) the fact that adding a variable to the class solved the problem. If you are worried about it, try doing a "Build->Clean" on the Debug build, and run it again. If it fails, you're still in trouble.
Chris Richardson
Programmers find all sorts of ingenious ways to screw ourselves over. - Tim Smith
|
|
|
|
|
Yes. I did add the GetDocument to my second view. That was the first thing I did since you told me about it. If you are saying that its not good to do:
CBKDoc * pDoc = (CBKDoc *)GetDocument();
, then what should one do? I've always seen it this way. This is the cast you are talking about right? Are you saying that I should just do:
CBKDoc * pDoc = GetDocument();
since it returns the right thing anyways? It does the cast too......(CBKDoc*)m_pDocument
CBKDoc* CSearchView::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBKDoc)));
return (CBKDoc*)m_pDocument;
}
#endif //_DEBUG
Appreciate your help,
ns
|
|
|
|
|
I'm write a application with two threads which are sender and receiver to send and receive data :
//Global
CSocket send_sock, recv_sock;
//These two sockets were created some where at start up
//before creating two threads : sender and receiver
// send_sock.Create(0, SOCK_DGRAM);
// recv_sock.Create(1111, SOCK_DGRAM);
//Sender thread
int sender(LPVOID)
{
while(bFlag)
{
//Some code here
send_sock.SendTo(data, size, port, addr);
//Some code here
}
}
//Receiver thread
int receiver(LPVOID)
{
while(bFlag)
{
//Some code here
recv_sock.ReceiveFrom(data, size, addr, port);
//Some code here
}
}
The sender runs ok but the receiver can not. The receiver just returns an error (WSAWOULDBLOCK) at the ReceiveFrom statement.
To solve this problem I use a socket variable as a local variable in the receiver function :
int receiver(LPVOID)
{
CSocket sk;
sk.Create(1111, SOCK_DGRAM);
while(bFlag)
{
//Some code here
sk.ReceiveFrom(data, size, addr, port);
//Some code here
}
}
So it runs ok in the 'Share MFC DLL' compile mode, it can not run in the 'Static MFC DLL' compile mode.
I don't know why because I'm starting with Window Socket.
So many problems to me. Please help me. Thanks in advance.
|
|
|
|