469,299 Members | 2,050 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

Testing for S_FALSE without exception handling

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,

Jun 4 '07 #1
5 3856
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"mungflesh" <ro************@yahoo.co.ukwrote in message
news:11**********************@o11g2000prd.googlegr oups.com...
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,

Jun 4 '07 #2
On 4 Jun, 16:49, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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,

Jun 4 '07 #3
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();
}
}
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"mungflesh" <ro************@yahoo.co.ukwrote in message
news:11**********************@d30g2000prg.googlegr oups.com...
On 4 Jun, 16:49, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
> 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,

Jun 4 '07 #4
On 4 Jun, 17:08, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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,

Jun 4 '07 #5
Yes, it works. Thanks for the tip.

Jun 7 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by adi | last post: by
6 posts views Thread by Shabam | last post: by
3 posts views Thread by Master of C++ | last post: by
44 posts views Thread by craig | last post: by
24 posts views Thread by David | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.