|
Does the following seem appropriate...?
Type* temp = m_pBuff;
try{
m_pBuff = (Type*)HeapReAlloc(m_hHeap, HEAP_ALLOC, m_pBuff, nHeapSize);
}
catch(...){
bFull = TRUE;
m_pBuff = temp;
}
Any suggestions?
TIA
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
As it stands, HeapReAlloc does not throw any exception (it returns NULL on failure), so your exception handler will never be called. You can add the flag HEAP_GENERATE_EXCEPTIONS to indicate HeapReAlloc to throw on exception if it fails, but even so the technique is probably more expensive (in computational terms) than the simpler check against NULL (IMHO).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
HEAP_ALLOC macro actually expands
HEAP_NO_SERIALIZE | HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY
sorry bout that.
I can't for some reason get HeapAlloc/ReAlloc to return NULL
even if i try it with 2,000,000,000 byte request it succeeds(without GEN_EXCEPTIONS)...but the exception fires, so i dunno...
Other than this...is everything OK...?
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
It's weird what you're saying... You might try calling GetExceptionCode in the handler to see what exception is being thrown (STATUS_NO_MEMORY or STATUS_ACCESS_VIOLATION ).
Other than this...is everything OK...?
I guess it is, but this is surely masking some underlying problem that probably will strike back in some other form sooner or later. I'd suggest you investigate the reasons why HeapReAlloc seems to behave differently depending on whether it is raising exceptions or not.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
In an application, I have used a class derived from CHtmlView. I wish to perform the typical find operations on it i.e. find a word and highlight it, find the next occurrence of the word, find the previous occurrence of the word.
Whenever I use the function findText of IHTMLTxtRange, with the parameter "forward " set to a +ve value, the forward search occurs correctly. But if I use the function with a negative value of forward, then the function doesnt work. (although it should,as per the documentation)
WHAT MAY BE THE REASON?
HERE IS A CODE SNIPPET OF WHAT I DID:
IHTMLDocument2 *lpHtmlDocument = NULL;
LPDISPATCH lpDispatch = NULL;
lpDispatch = m_pHelpDataView->GetHtmlDocument();
ASSERT(lpDispatch);
lpDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&lpHtmlDocument);
ASSERT(lpHtmlDocument);
lpDispatch->Release();
IHTMLElement *lpBodyElm;
IHTMLBodyElement *lpBody;
IHTMLTxtRange *lpTxtRange;
lpHtmlDocument->get_body(&lpBodyElm);
ASSERT(lpBodyElm);
lpHtmlDocument->Release();
lpBodyElm->QueryInterface(IID_IHTMLBodyElement,(void**)&lpBody);
ASSERT(lpBody);
lpBodyElm->Release();
lpBody->createTextRange(&lpTxtRange);
ASSERT(lpTxtRange);
lpBody->Release();
CComBSTR search(FindName.GetLength()+1,(LPCTSTR)FindName);
bool bFound,bTest;
long t;
***lpTxtRange->findText((BSTR)search,forward,bMatchCase+bMatchWholeWord,(VARIANT_BOOL*)&bFound);
........
***lpTxtRange->select();
|
|
|
|
|
1)the caret will be destroyed by system? or should be destroyed by programmer?
2)if there is two mdi child windows, one is closed, which message need to be handled to show the caret on the other mdi window? even i don't know how to
process the OnActivateView method.
|
|
|
|
|
DestroyCaret() should be called in the WM_KILLFOCUS by the programmer.
If my memory serves me correctly
WM_SETFOCUS
CreateCaret()
SetCaretPos()
ShowCaret()
WM_PAINT
HideCaret()
WM_KILLFOCUS
DestroyCaret()
HTH
cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
what does the method OnActivateView serve as?
i did as you said, but when i close one view, the other view won't set its caret, why? but if i use another program such as MS VC ++ and then change to it, the caret is here, how to resolve it?
thanks
one is the other who absorbs the thoughts of others
|
|
|
|
|
ooze wrote:
what does the method OnActivateView serve as?
Sorta like an ActiveX event. You override the function to supply custom handling when it's called by the framework.
ooze wrote:
i did as you said, but when i close one view, the other view won't set its caret, why?
Do you have the appropriate code in both view's OnSetFocus/OnKillFocus...?
p.s-In WM_PAINT hide your caret at start and Show at finish.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
here is the code in OnSetFocus, and onKillFocus
CView::OnSetFocus(pOldWnd);
// TODO: Add your message handler code here
if(CONNECTED)
{
::CreateCaret(this->m_hWnd ,0,ftWidth,ftHeight);
SetCaretPos(CPoint(xCurPos,yCurPos));
::ShowCaret(this->m_hWnd );
}
CView::OnKillFocus(pNewWnd);
// TODO: Add your message handler code here
DestroyCaret();
one is the other who absorbs the thoughts of others
|
|
|
|
|
Code looks fine, however here are some suggestions.
Make sure CONNECTED is true and use all hardcoded values just to make sure everything is prim and proper.
if(TRUE)
{
::CreateCaret(this->m_hWnd, NULL, 1, 20);
SetCaretPos(CPoint(10,10));
ShowCaret();
}
I've had problems with caret functions only to realize variables weren't holding proper values, so make sure
(i'll assume ftWidth is font width)
ftWidth is actually non-zero each call, as with the other vars.
I've never used carets in MDI apps, however I don't see any difference then SDI...
HTH;P
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
all the question now is when i close one MDI View, the other MDI view wont display the Caret, but when it is overlapped or covered by other programs,
it will display it right
why?
thanks for your suggestion
one is the other who absorbs the thoughts of others
|
|
|
|
|
That problem I have had and I can't say forsure why this is
I only found a quick hack and it worked so I went with it...
If the caret appears when you move something over it or resize the window, it's obvious it's a OnPaint not getting called at appropriate times.
So what i did was call the views Invalidate() member
Try this it should work
I guess call it from with the other views OnKillFocus...?
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I want to write a cd burn or cd maker program which can create the .iso .bin .cue files and burn it to the cdr(w).
But I can't find any reference to this. Could anyone give me an idea?Maybe the format reference? The source code,url are even good.
BTW:The source code I got are under cygwin. I need the true win32. Thanks.
|
|
|
|
|
It's been a while but try visiting the Wotsits file format collection
Wotsits
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
OK, this has probably been asked a 1000 times, so here we go with number 1001. I've been programming C++ for about 5 or so years now, and have yet to find a decent explanation of the various casting operators (reinterpret_cast<>, const_cast<>, etc.). Not to say that several don't exist on here, I just couldn't find them. So, my question is can anybody explain what each of the different C++ cast operators do? Are they part of the language, or do they belong to the STL? Where would I find a good explanation or two here?
Thanks in advance.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
They are part of the core language, and const_cast removes constness, reinterpret_cast allows casting bewtween unrelated types, static_cast does not return NULL if a cast fails, and dynamic_cast does. I'm sure there's a bit more to it than that, but I find myself using dynamic_cast the most, so it's the only one I know really well.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
They are keywords of the language. Short explanation:const_cast<> removes away const ness.
static_cast<> is used for conversions that, although well defined in C++, are not automatically applied by the compiler. Most important examples are truncating arithmetic castings (eg. from double to int ) and casting from a base class pointer to a derived class pointer.
dynamic_cast<> plays a role similar to that of static_cast<> when downcasting from a base class to a derived one, but it has the important difference that the downcasting is checked for validity at run-time, ie. dynamic_cast<> returns 0 if what you are trying to downcast to say A* is not actually a A* . For this to work, classes passed to dynamic_cast<> must be polymorphic, ie. they must have at least one virtual function.
reinterpret_cast<> is used for anything else, as conversions with no defined meaning in the standard, like for instance converting a pointer to an int .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
const_cast also removes the volatile attribute.
--Mike--
"Everyone has figured out what 'service pack' really means, so they had to go and change the language. Perhaps this is what Bill was talking about in the 'security is top priority' letter."
-- Daniel Ferguson, 1/31/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
Bien sure
I forgot also to mention that dynamic_cast<> can be used not only for downcasting, but also for "crosscasting" across a multiple inheritance hierarchy: eg, if AB is an A as well as a B , a dynamic_cast<B*> on a A* will succeed when the object pointed to is an AB .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
dynamic_cast<> plays a role similar to that of static_cast<> when downcasting from a base class to a derived one, but it has the important difference that the downcasting is checked for validity at run-time, ie. dynamic_cast<> returns 0 if what you are trying to downcast to say A* is not actually a A*. For this to work, classes passed to dynamic_cast<> must be polymorphic, ie. they must have at least one virtual function.
Just want to add that dynamic_cast can be used for references also but in this case if the cast fails, it will throw a bad_cast exception (because there is no such thing as a bad reference)
Here's a link that explains the various casts in more detail: http://www.gotw.ca/gotw/017.htm
Chen Venkataraman
|
|
|
|
|
Thanks all. That clears it up quite a bit.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
i've connected the ODBC database in my app (quite easy)....but how do i generate reports thru my application or is there any way i can call Access to generate reports for me? suggestions, codes or books all welcome? plz help..
|
|
|
|
|
I think the only way is to read each record by your application and create report.you can find good information here:
http://lnrpc2.irb.hr/ebooks/0672313502/index.htm
Mazy
You can find a solution (even a foolish one) for all problems (even big ones)
|
|
|
|
|
Hi,
just you see this one may be useful for you.
Printing with MFC Made Easy by Dan Pilat in printing option of this site.
Also you can try with Crystal Reports .
anju
|
|
|
|