When a component using Automation causes an error, it can return an object to describe that error. To do this, the component makes the following calls:
The following code shows an example of how an Automation component might create an Automation error object and transfer ownership of the object to the Automation DLL.
#include <oledb.h>
int main() {
ICreateErrorInfo *pcerrinfo;
IErrorInfo *perrinfo;
// Error occurs in a method in the provider. (Not shown.)
//Create an Automation error object.
CreateErrorInfo(&pcerrinfo);
// Use the returned ICreateErrorInfo interface pointer to add error information to
// the object. (Not shown.)
// Retrieve an IErrorInfo interface pointer on the object and call SetErrorInfo to
// pass the error object to the Automation DLL.
pcerrinfo->QueryInterface(IID_IErrorInfo, (void**)&perrinfo);
SetErrorInfo(0, perrinfo);
// Release the interface pointers on the object to finish transferring ownership of
// the object to the Automation DLL.
perrinfo->Release();
pcerrinfo->Release();
} ;