Solved

Which include file defines COleDispatchException?

Posted on 2009-04-11
5
567 Views
Last Modified: 2013-12-14
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
Comment
Question by:wdoutre
  • 3
  • 2
5 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 125 total points
ID: 24124121
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 24124127
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
 

Author Comment

by:wdoutre
ID: 24124221
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 24124455
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
 

Author Comment

by:wdoutre
ID: 24132210
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question