Hey,
I'm sure you've had the occasion on which you developed an interesting application, and now required the ability to control it from the command line. The standard C/C++ functions for implementing various switches and input is nothing fun to work with, and the various template and composition based solutions are too complex most of the time.
Check out this interesting project:
http://www.codesynthesis.com/projects/cli/
You define the options you want in a very, very simple definition language, compile it into a C++ class file and voila: you can use it in your main() function.
Nice.
2009-10-29
2009-10-28
Catastrophic failure (Exception from HRESULT : 0x8000FFFF (E_UNEXPECTED))
Are you trying to use an ActiveX (OCX) control in a .NET application?
Did you add the reference, create a class and are quite happy at how easy it was?
So, now you try and run the application and CRASH - Catastrophic failure!!!
The problem is that an ActiveX control requires special handling when embedded into a .NET application. The easiest way to do this is:
1. When in the Form Designer, open the Toolbox window and right click one of the tabs.
2. Click "Choose Items..." menu option
3. Select the "COM Components" tab
4. Find your control in the list and add it.
5. Drag the control to your form.
This will create various new Interop classes, including special event handlers for your events, et cetera. It should work now.
Hurrah!!
Did you add the reference, create a class and are quite happy at how easy it was?
So, now you try and run the application and CRASH - Catastrophic failure!!!
The problem is that an ActiveX control requires special handling when embedded into a .NET application. The easiest way to do this is:
1. When in the Form Designer, open the Toolbox window and right click one of the tabs.
2. Click "Choose Items..." menu option
3. Select the "COM Components" tab
4. Find your control in the list and add it.
5. Drag the control to your form.
This will create various new Interop classes, including special event handlers for your events, et cetera. It should work now.
Hurrah!!
2009-10-22
map/set iterators incompatible
So, you've been working on some piece of code that employs STL containers, specifically a map. Perhaps you've also added some multi-threaded flavoring to pack a punch. Great.
Suddenly, you see this:
Ah, that's right. You have an iterator that points to the map's items, and are indeed iterating over them. The map is protected by a mutex, but - so as to not block for too long - you release and reacquire the mutex every iteration. Another thread then executes and clear()'s the map, rendering your iterator useless. You now compare it to the end() iterator, and voila - crash!
The solution? Make sure you don't invalidate your iterators while using them. That means - don't modify the STL container from another thread (even if you are using synchronization mechanisms) if you're not absolutely certain that you can and that you will not invalidate existing iterators. Operations like insert, erase and clear can invalidate iterators - read the details at each container's documentation page.
Suddenly, you see this:
Debug Assertion Failed!Strange. What just happened? Did you just mix the iterators of different classes together? No, you're certain you used map iterators, not set iterators. Everything SEEMS well...
Program: C:\....\Test.exe
File: C:\Program Files\Microsoft Visual Studio 8\VC\include\xtree
Line: 293
Expression: map/set iterators incompatible
Ah, that's right. You have an iterator that points to the map's items, and are indeed iterating over them. The map is protected by a mutex, but - so as to not block for too long - you release and reacquire the mutex every iteration. Another thread then executes and clear()'s the map, rendering your iterator useless. You now compare it to the end() iterator, and voila - crash!
The solution? Make sure you don't invalidate your iterators while using them. That means - don't modify the STL container from another thread (even if you are using synchronization mechanisms) if you're not absolutely certain that you can and that you will not invalidate existing iterators. Operations like insert, erase and clear can invalidate iterators - read the details at each container's documentation page.
Subscribe to:
Posts (Atom)