Osiva Technical Notes

A reviewer at download.com suggested that osiva would be improved if you could drag and drop an image back into an explorer window, so that the images can be moved.  One of the problems with osiva is that you can't actually do any work  with it -- you can just look at pictures. Providing a drop source allows osiva to be used for basic image sorting. It also allows you to drop an image into your favorite image editor.

Adding a drop source to an MFC application is trivial, but osiva is written using just the windows API. Three COM interfaces need to be implemented to satisfy the file explorer: IDropSource, IDataObject, and IEnumFORMATETC. I packaged the implementations into a single module with an overly simple interface, dragsrc.cpp .

Dragsrc illustrates a few things:
  • To move the windows API into the object model, I've been using the standard trick of storing a pointer to "this" in the API  window structure. The Window Procedure is a simple proxy that resolves to a virtual handler in the class context.
  • The module has a built in isolation test, compiled if you define TESTING_DRAGSRC.
  • The interface between the module and its clients is as simple as possible. In this case it is actually too simple: the function returns 0, 1, or 2, and you cannot figure out what those mean unless you read the comments at the top of the module. There should certainly be an include file with a function prototype and definitions for the return codes, but for this freeware application I will not write one. Adding an include file here doubles the number of files involved, for a very small advantage.