Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Will try/catch work with API functions?
In my current project I create a few menus on the fly and have a LOT of "if" statements to handle the API functions failing. Is it possible to group these into a big "try" block?
AppendMenu(this->hFileMenu, MF_ENABLED | MF_STRING, 1001, L"&Import");
AppendMenu(this->hFileMenu, MF_ENABLED | MF_STRING, 1002, L"&Export");
AppendMenu(this->hFileMenu, MF_ENABLED | MF_STRING, 1003, L"&Backup");
AppendMenu(this->hFileMenu, MF_ENABLED | MF_STRING, 1004, L"E&xit");
while(GetMenuItemCount(this->hFileMenu) > 0)
DeleteMenu(this->hFileMenu, 0, MF_BYPOSITION);
This will save a TON of checking if it works. Note that "AppendMenu()" is of type "BOOL", not "bool". That means that it is an integer return value, not a single bit.