Just wasted a few hours of my life with a seemingly
trivial segment of code. Spot the error:
HRESULT hrInit = CoInitialize(NULL);
CUserProfileWebService webService;
webService.Execute();
if (SUCCEEDED(hrInit))
CoUninitialize();
I was getting an Access Violation when the application exited, which means I was trying to access memory that no longer belonged to me. Turns out, the problem was due to scope. The "
webService" object doesn't fall out of scope until
after CoUninitialize has been called, so it doesn't know to clean itself up until it's too late. The fix is to enclose the webService variable in it's own scope, such as the following:
HRESULT hrInit = CoInitialize(NULL);
{
CUserProfileWebService webService;
webService.Execute();
}
if (SUCCEEDED(hrInit))
CoUninitialize();
In this instance, “
webService” will clean itself up immediately after the
} curly brace. Of course, it took
forever to narrow it down to these five lines of code, at which point I realized my mistake. *sigh*
1 comments:
Casinos Near Me - DrmCD
This 시흥 출장마사지 map shows 울산광역 출장안마 the closest 김천 출장마사지 casinos to me. Find your nearest casinos with DrmCD. Find the best 경기도 출장마사지 casinos near you from your phone, tablet, or tablet 강원도 출장마사지 today!
Post a Comment