Information générale
Catégorie:
COM/DCOM et OLE Automation
Titre:
Does ComReturnError work or not?
So, I've got a VFP COM object and there's an initialize method that I put a comreturnerror(_vfp.servername,'hello world') in to test how my C# program catches that exception with this code:
**************************************************************C#
public static dynamic Instance
{
get
{
mvlib = Activator.CreateInstance(Type.GetTypeFromProgID("VMV.MVLIB"));
object[] initialPath = { ConfigurationManager.AppSettings["MyPath"] };
bool initReturn = false;
try
{
initReturn = mvlib.Initialize(initialPath);
}
catch (COMException ce)
{
var msg = ce.Message.ToString();
}
catch (Exception ce)
{
var msg = ce.Message;
}
finally
{
}
more code...................
**************************************************************
I've got two catch's one for COMException and the 2nd for regular Exception. The COMException does not catch the error. The error that is caught has this message:
System.NullReferenceException : Object reference not set to an instance of an object.
Which is not at all helpful and doesn't seem to reflect the message I put in my ComReturnError().
The VFP Help for ComReturnError has this warning:
(For advanced users) COMReturnErrorInfo fills in a COM exception information structure. This is used only for IDispatch (late binding calls). If you call the server via early binding and the client passes a COM exception structure to the server, there is no error mechanism to return the error info unless the client does a QueryInterface on the ISupportsErrorInfo interface.
I saw something in my Google searches that says that C# Dynamic objects like a VFP COM object don't really use late binding, which I think I believe. I am clueless as to how to use C#'s QueryInterface and the ISupportsErrorInfo interface, but understand the concepts. I haven't found any C# samples to copy.
So, does anyone have experience with ComReturnError?
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement