Testing for S_FALSE without exception handling

  • Thread starter Thread starter mungflesh
  • Start date Start date
M

mungflesh

Hi there,

Is there a way of testing for an S_FALSE return from an existing
unmanaged COM server, without using a try .. catch and without having
to manually modify the MSIL?

eg. is there some general setting to use with tlbimp to have the
PreserveSig effect?

Thanks,
 
As you have seen, there isn't a way to get tlbimp to add the PreserveSig
attribute to methods so you can get a return value of S_FALSE.

However, there is no reason you can't define the COM interface in code,
and then have the signature return the HRESULT to you, attaching the
PreserveSig attribute yourself to it. You can cast the COM object to that
interface definition just as you would to one produced by TLBIMP.
 
As you have seen, there isn't a way to get tlbimp to add the PreserveSig
attribute to methods so you can get a return value of S_FALSE.

However, there is no reason you can't define the COM interface in code,
and then have the signature return the HRESULT to you, attaching the
PreserveSig attribute yourself to it. You can cast the COM object to that
interface definition just as you would to one produced by TLBIMP.


I have not fully understood yourt suggestion. When you say "define the
COM interface in code", do mean re-implement it on the .NET side ?

Thanks,
 
Well, when you use TLBIMP, you have already implemented the interface on
the .NET side. =)

I'm saying define it in code, like this:

namespace MyNamespace
{
[Guid("<interface id>")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)] // Or whatever is
appropriate here.
[ComImport] // If the interface was previously defined in a type
library.
public interface IMyInterface
{
[PreserveSig]
int MyMethod();
}
}
 
Well, when you use TLBIMP, you have already implemented the interface on
the .NET side. =)

I'm saying define it in code, like this:

namespace MyNamespace
{
[Guid("<interface id>")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)] // Or whatever is
appropriate here.
[ComImport] // If the interface was previously defined in a type
library.
public interface IMyInterface
{
[PreserveSig]
int MyMethod();
}

}

Ok, I see. I'll send you an HRESULT to let you know how I get on. :-)
Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top