• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 617
  • Last Modified:

Which include file defines COleDispatchException?

This seems like a simple question, but I'm having trouble finding the answer.  

I'm developing a Win32 console application that controls a camera through that camera's SDK.  In the SDK documentation it says that camera errors will throw COleDispatchExceptions.  When I try catch the COleDispatchException in Visual Studio 2008, I get the following error message:

error C2061: syntax error : identifier 'DispatchException'

The Visual Studio project is a simple Win32 project, not an MFC project.  Is COleDispatchException only defined in MFC projects?  I tried changing it to an MFC project but ran into other include errors, so I'd rather not go that route.

The syntax of my call is in the code snippet below
try
{
	Connect(driverId); //SDK method that works as long as my camera is turned on
}
catch (COleDispatchException  e) {
	printf("Excpeption connecting to camera: \n");
}

Open in new window

0
wdoutre
Asked:
wdoutre
  • 3
  • 2
1 Solution
 
DanRollinsCommented:
afxdisp.h
Two ways to find out this sort of thing.  
1) Go to the VS directory and use the Windows Explorer to Search for files *.h that include the text (in this case COleDispatchException)
2) Look at the documentation.  The required headers are always listed
   http://msdn.microsoft.com/en-us/library/zdbad761(VS.71).aspx
 
0
 
DanRollinsCommented:
And Yes, it is an MFC object.
What is the Connect function? It does not appear to be a Win32 API function. If I could see the docs on that I could probably tell you how to handle the exceptions it throws.
0
 
wdoutreAuthor Commented:
I tried #1, but the machine I'm on is messed up and won't search the hard drive.  Thanks for #2.

I'm now running into problems compiling and/or linking my project though by getting this error:

afxv_w32.h(16) : fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>

I am not explicitly including afxv_w32.h and this error doesn't show up until I include afxdisp.h.  If I edit my include to encapsulate it as shown in my snippet, then I can compile, link, and run successfully.

This seems dangerous, but when looking at windows.h it doesn't do anything unless _WINDOWS_ is not defined, so I guess I'm okay?  I can't see anywhere else that I'm including afxdisp.h and it doesn't occur if I omit that include, so I don't know what's going on.
#ifndef WINVER
	#define WINVER 0x0501 //Windows XP
#endif
 
#ifndef __AFXDISP_H__
	#undef _WINDOWS_	
	#include "afxdisp.h"
#endif
 
#ifndef _WINSOCKAPI_
	#include <winsock.h>
#endif

Open in new window

0
 
DanRollinsCommented:
Is there a reason that you did not answer my question?  
If you are not using other MFC objects, there may be no reason to use MFC.
0
 
wdoutreAuthor Commented:
Sorry I didn't answer your question.  I had my comment open for a long time while I walked through things making sure I was covering everything.  When I finally posted your comment had already been there.

The Connect method is to connect to an Olympus digital camera, via USB driver.  

The documentation for the camera's SDK says that it throws either a proprietary error, or a COleDispatchException.  In practice, it throws either the proprietary error (which I can catch fine) or something that is not a COleDispatchException which crashes my program even if I try to catch (...).
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now