Link to home
Start Free TrialLog in
Avatar of wdoutre
wdoutre

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of wdoutre
wdoutre

ASKER

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

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.
Avatar of wdoutre

ASKER

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 (...).