Link to home
Create AccountLog in
Avatar of StanChart
StanChart

asked on

Funky COM error

Hi,
I have an application that calls functions in other applications using COM.  Whenever I call such a function, I always put a try {} catch (_com_error &er) {} around it.  Whenever there is an error, I display a message box with er.Description() on it.  

I received an email from one of my app users who received an error where er.Description() had all sorts of funky characters in it which leads me to believe that there was some sort of corruption.

Anyone know how/why this would happen?
Avatar of bijopuli
bijopuli
Flag of India image

Hi StanChart

Just try this function to display ur message .

er.ErrorMessage( );

eg:

AfxMessageBox(er.ErrorMessage( ));

Regards
Bijo.
Avatar of StanChart
StanChart

ASKER

Either way, the message would have contained garbage data.  I'm interested in finding out why it contained that data.  All other times, the message displays a valid error.
I use er.Description because I add other text to the message.
ASKER CERTIFIED SOLUTION
Avatar of bijopuli
bijopuli
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of jkr
Check all the places where your throw a _com_error and have a close look at those where you build a complex error message with parameters - you will most likely find the culprit there, with one of these parameters being either screwed up or invalid.
Hi StanChart, as Bijo pointed out there are many strange things that could happen to e.Description while building the MessageBox. Therefore it could be helpful if you could post the piece of code that displays the message box.

In the meanwhile, let me make a wild guess: could it be so that the user works with some strange language version of WiIndows, and the fonts he have cannot render the message correctly?
The code looks something like this:

try
{
      // some code
}
catch (_com_error &er) {
      CString error =
            CString("There was an error ... ") +
            CString("on ... \"") + CString(m_pMyPtr->GetName()) + CString("\".\n\n") +
            CString(string(er.Description()).c_str()) + CString("\n") +
            CString(er.ErrorMessage());
      MessageBox(NULL, error, "My App Error", MB_APPLMODAL|MB_ICONERROR|MB_OK);
      return FALSE;
}

Let me know if you spot an error.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup Zone:
  Split: alexcohn {http:#18637089} & bijopuli {http:#18625195}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Sean Durkin
Experts Exchange Cleanup Volunteer
Forced accept.

Computer101
EE Admin