Question

I wrote my routines for using CDO.Message. It's working long time ago. But now, in some site they installed a certificate and then the priorly working version is making errors with all calls.

I used simple variants to hold the CDO.Message COM object.

When I used Send method(?) it returns a HResult. But it's interesting, because the HResult is unusable for get the error code, because the Send is seems to be a real method which makes Exception on problems. So the result code is -1 if I set to this value before.

I tried to get the last error code with GetLastError. But this is 0.

I can catch the Exception, but it contains only the error message what is:

"The transport failed to connect to the server"

The VB codes can get the error code which could provide extra information about the problem (or not).

Do you know about a technic to get the error code value from Delphi XE3?

Was it helpful?

Solution

It would be better if we had some source code at hand. Specifically the Delphi declaration of the COM interface.

My guess is that the method is declared as safecall. What this means is that the compiler understands that the method is actually stdcall returning HRESULT, and re-writes the parameters to match. If the true COM method returns an HRESULT other than S_OK then the compiler writes code to check for that and convert the error into an exception.

The exception that is raised will be EOleSysError and that has the property ErrorCode which contains the HRESULT that you are looking for.

So, you need to:

  • Add an exception handler to catch EOleSysError.
  • Read the ErrorCode property of the EOleSysError exception instance that you catch.

This is all a little bit round the houses. If you'd prefer to avoid exception handling, then you can always re-write the COM interface declaration to be a true stdcall method returning an HRESULT.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top