Apr 11, 2012 at 2:26am UTC
How would you convert the macro below to inline code?
//macro...
#define CATCHERROR(ptr,a) catch(_com_error &e)\
{\
ErrorHandler(e,m_ErrStr);\
ptr=NULL;\
return a;\
}
//code snippet...
1 bool Open(char* UserName, char* Pwd,char* CnnStr)
2 {
3 try
4 {
5 HRESULT hr;
6 hr = m_Cnn.CreateInstance( __uuidof( ADODB::Connection ) );
7 m_Cnn->Open(CnnStr, UserName, Pwd, NULL);
8 }
9
10 CATCHERROR(m_Cnn,0)
11
12 sprintf(m_ErrStr,"Success");
13 return 1;
14 }
I replaced line 10 above
10 CATCHERROR(m_Cnn,0)
With...
10 catch(_com_error &e){ErrorHandler(e,m_ErrStr); return 0;}
and it seems to work......... BUT NOTICE THAT ... ptr=NULL
in the macro was simply left out of my replacement code...
Should the replacement code be...
10 catch(_com_error &e){ErrorHandler(e,m_ErrStr); e=NULL; return 0;}
This seems to compile and run... but I'm on shaky ground here learning about macro's...
So, thanks for any help from a more knowledgeable source in resolving this.
Last edited on Apr 11, 2012 at 4:20am UTC