I have this function inside my program:
void CBar::NavigateComplete2(IDispatch *pDisp, VARIANT *URL)
{
try {
UpdateBar(UpdateNavigateComplete);
} catch (...) {
ASSERT(0);
}
}
I need to have the URL value from URL->bstrVal from this function and to copy it to a global variable so that my other function can easily refer to it.
What is the appropriate way to do this? since my current method destroys the stability of my program..it crash all the time.
I’m not sure I understand the question or the motivation. If all you want to do is, as described in the question, copy the value of
URL->bstrValthen the simplest way to to use a wrapperBSTRclass for the global.Otherwise you should use a raw
BSTRand copy it withSysAllocString(and don’t forget toSysFreeStringit when you’re done with the global.If you don’t copy the string (and only copy the pointer) the
VARIANT‘s owner will destroy it giving you a global with a dangling pointer.