|
Sorry i left out the following line before returning from the try
RaiseException(0,0,0,0);
This is just a sample that creates the problem
Thanks for your reply
If i raise the exception manually i don't understand why the variable is corrupted.
|
|
|
|
|
AFAIK direct use of the 'RaiseException' API isn't really appropriate to throw a C++ exception, which is what catch (...) will catch.
This function always prints 'nRetCode = 99'.
void TestFn ()
{
int nRetVal = 0 ;
try
{
nRetVal = 99 ;
throw 0 ;
nRetVal = 1 ;
std::cout << "nRetVal = " << nRetVal << std::endl ;
}
catch ( ... )
{
std::cout << "nRetVal = " << nRetVal << std::endl ;
}
}
Perhaps your problem is down to a conflict between some Structured Exception Handling boilerplate in ATL and C++ exceptions?
Paul
|
|
|
|
|
Never knew that, thanks got rid of RaiseException and replaced with a throw, and the problem went away.
Thanks Again
|
|
|
|
|
I Have created an IE ToolBand, NON MFC, and I careted Owner Drawn Menu,
now my problem is, When I click on Owner-Drawn menu, I happen to see that my address bar dosent open the desired URL , It shows DONE on LHS and Progress bar is set to zero, DID any one encountered such problem, How to solve it..
regards
Balkrishna Talele
|
|
|
|
|
Hello everyone:
I made a combo box in a WTL tree view, when the WM_LBUTTONDOWN happened , how can i know whether the list box of combo box is clicked?
Thank you.
-Freehawk.
|
|
|
|
|
hi
Did you try by subclassing the listbox and editctrl on OnCtlColor . chk the MSDN knwoledge base article with id Q174667 for more details.
rgds..mil10
|
|
|
|
|
Hi!,
I want to create a read-only view of excel,word or powerpoint file using the ole techonology.
I use the default object handler provided in ole32.dll
I dont know what steps to follow after creating the object using:
hr=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_HANDLER,
IID_IUnknown,(PVOID*)&pUkwn);
the object handler basically implements IDataObject,IOleCache and IViewObject.
IViewObject::Draw will draw on the specified device.
but before that I want to pass data to the object.
which interface shall I use?
thanks
Anshuman
|
|
|
|
|
I am using ATL with Visual Studio.NET 2003. I seem to be having a problem
with template member specialization involving the CComPtr<> class declared
in atlcomcli.h. In the declaration for CComPtr<> the last entry for a
member function is:
template <>
T* operator=(const CComPtr<T>& lp) throw()
{
return static_cast<T*>(AtlComPtrAssign((IUnknown**)&p, lp));
}
The code I am working with declares a template member specialization similar
to this:
CFoo* CComPtr<CFoo>::operator=(const CComPtr<CFoo> & lp)
{
...
}
In VS.NET 2002 this works just fine. However, in VS.NET 2003 I get compiler
error C2511 (overloaded member function not found ...). I can remove the
line 'template <>' from the CComPtr<> class declaration in atlcomcli.h
(shown above) and the code will then compile just fine. Is this a bug in
ATL or is there something I am not seeing?
Since I don't want to modify the original ATL files, I have made special
modified copies of atlcomcli.h and, by necessity, atlbase.h and I have
included them in the project in order to do a workaround. Is there a better
way?
Thank you,
Ray Gregory
|
|
|
|
|
In standard C++, you can't just specialize a single member function of a template class. You have to specialize the whole class template. Earlier versions of Visual C++ erroneously allowed this.
Why do you need to specialize CComPtr ? You should normally be using this class with COM interfaces; if you're trying to use it with something else, I suggest writing a smart pointer template of your own. Using CComPtr with something that isn't a COM object will just confuse people.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
I have found that I can specialize the single member function just by removing the line 'template <> ' that immediately precedes the declaration of the operator= function in the delcaration for CComPtr in atalcomcli.h.
I have to specialize the operator= member function of CComPtr to avoid a compiler error about ambiguous conversions. The specialized function does the same thing as the default function with the exception of some typecasting.
|
|
|
|
|
The class CFoo is a COM interface. It inherits multiply from, among other things, IDropSource and IDropTarget . In fact this is the reason I need to specialize the asignment operator for CComPtr<CFoo> . If I don't, then the compiler signals ambiguous conversions between CFoo* and IUnknown* because both IDropSource and IDropTarget derive from IUnknown .
Unfortunately, the specialized copy asignment operator breaks in VS 2003 but not in VS 2002.
|
|
|
|
|
Could you show the lines that give the ambiguous conversion error?
Thank You
Bo Hunter
|
|
|
|
|
Hi,
warning: this is sort of a newbie question!!!
I've got a list of pointers in a class which I often need to clear, I've tried the clear and remove methods but these only clear the entries from the list and dont actually delete the objects that the pointers point to. The way that I'm currently deleting these objects is by iterating through the list assigning the iterator to a local variable which is of the same type of the list variables. I then remove the iterator from the list and then delete the local variable ( delete ( *it ) ; doesnt work hence local variable). I then set the iterator to the beginning of the list and start the process all over again (assuming I havent reached the end of the list).
Is this the correct way of doing this? (it just seems very long winded and overly complex for something which must be common in most programs).
many thanks,
|
|
|
|
|
delete( *it ) should work, but you should probably do it in two stages: first delete the objects pointed to, then delete the list elements (the pointers themselves). My RemoveAll would probably look something like:
for ( list<int*>::iterator it = l.begin();
it < l.end();
++it )
{
delete( *it );
}
l.erase( l.begin(), l.end() ); where l is a list<int*>
[EDIT] To make it clear, I think the problem you're having is that you're deleting the current element, pointed to by this iterator, before moving to the next element, so the iterator can't get the next element. You could handle this in the classic linked-list fashion, by retrieving the next value of the iterator before deleting this one. [/EDIT]
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
cheers,
I'll give your code example a try tonight (knew there had to be an easier way ).
|
|
|
|
|
|
|
I've used this approach in the past,
struct DeleteObjectHelper
{
template< typename T>
void operator ()( const T* p ) const
{
delete p ;
}
template< typename K, typename T>
void operator ()( const std::pair< K, T>& p ) const
{
delete p.second ;
}
} ;
template <class C> EmptyContainer ( C& c )
{
std::for_each ( c.begin (), c.end (), DeleteObjectHelper ) ;
c.clear () ;
}
then it's used thus,
std::list<MyClass *> MyList ;
EmptyContainer ( MyList ) ;
std::map< std::string, MyClass * > MyMap ;
EmptyContainer ( MyMap ) ;
Paul
|
|
|
|
|
Not surprisingly, I suggest my little functor[^]
for_each(myList.begin(), myList.end(), free_ptr<MyClass>());
myList.clear();
|
|
|
|
|
I am confused and why I can not store information in an object. If I want to save this information what I have to do?
#include <list> std::list<rect> MyList;
RECT rc = {0,0,0,0};
MyList.push_back(rc);
std::list<rect>::iterator it = MyList.begin();
RECT& RectOne = (RECT) *it;
RectOne.left = -1;
RECT& RectTwo = (RECT) *it;
int left = RectTwo.left;
RectOne is reference to first element of the RECT container. I changed the value of the first element of the container, and look the value in RectTwo, but it didn’t change the value. Real confused.
Agha Khan
|
|
|
|
|
What appears to be happening is that due to the cast
RECT& RectOne = (RECT) *it; the compiler is generating a temporary object which is a copy of the object referred to by the return value of *it , then binding the reference RectOne to that temporary RECT object. Similarly, RectTwo is bound to a different temporary object.
The answer is simple: remove the casts. The compiler no longer generates temporaries, and both references are bound to the original object.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hi Agha,
Mike is absolutely right and I can tell you why, you are doing the wrong cast. You have a reference to a RECT and you are casting to a RECT.
This is what you should do, if you want to keep the cast
RECT& RectOne = (RECT<big><big>&</big></big>) *it;<br />
RectOne.left = -1;<br />
<br />
RECT& RectTwo = (RECT<big><big>&</big></big>) *it;<br />
int left = RectTwo.left;
Regards,
Fabian
|
|
|
|
|
Hi!,
I am developing a container for embedding Miscosoft Word documents.
I am using CoCreateInstance()to create object,
after creation I set the clientsite and with the help of IPersistInterface::Load I load the storage, at this moment a temporary file having extension .doc is created in the Temp folder.
I want to avoid the creation of the temporary .doc file in the Temp folder.
and I also want to know the reason as to why the temporary .doc file is created.
Thanks
Anshuman
|
|
|
|
|
Hi all
In my COM server i had an events what pass iterface as parameter
[...]
dispinterface _IMyObjectEvents{
methods:
[..]Event1([in]IMyInterface* pIface);
};
For this event ATL master generate code like this
class CProxy_IMyEvents<...>{
...
HRESULT Fire_Event1(IMyInterface* pIface)
{
for(...)//looking for all connected clients
{
...
CComVariant avarParams[1];
avarParams = pIface;//Invoke AddRef() for pIface
...
pConnection->Invoke(...);//Invoke this event for client
}//Invoke Release() for pIface by CComVariant destructor
}
So far as i know client should release all methods param (marked as [in])by oneself.
But in this code interface released by server.
Please clear up this subject for mee.
Thanks
|
|
|
|
|
In this particular case, the server (which is firing the event), is acting as a client to the event subscriber. A client is a caller, a server is a callee.
Clear?
Steve S
|
|
|
|