472,790 Members | 3,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,790 software developers and data experts.

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 3985
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Bill Davidson | last post by:
Hi there, Please forgive me for posting this article on multiple groups. Being new in the newsgroups, I was not sure which group would have been appropriate for my question. Sorry. My...
11
by: adi | last post by:
Dear all, This is more like a theoretical or conceptual question: which is better, using exception or return code for a .NET component? I had created a COM object (using VB6), which uses...
6
by: Shabam | last post by:
A web application of mine developed using C# + MS SQL runs fine normally. However when I stress test it with a load testing software (using about 60 simultaneous users) some instances start...
7
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
6
by: Vikram Paranjape | last post by:
Hi, I wrote a small test script to utilize the ScopeGuard class from the Dec 2000 CUJ article. I noted that my cleanup function was being called on normal block exit, but not on calling a...
3
by: Master of C++ | last post by:
Hi, I am an absolute newbie to Exception Handling, and I am trying to retrofit exception handling to a LOT of C++ code that I've written earlier. I am just looking for a bare-bones, low-tech...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
7
by: Ralf Gedrat | last post by:
Hello! I have some Vb.Net applications, which are terminated at indefinite times without message. If I call in the program regulated system.GC.Collect, then the program is terminated here...
24
by: David | last post by:
Hi list. What strategies do you use to ensure correctness of new code? Specifically, if you've just written 100 new lines of Python code, then: 1) How do you test the new code? 2) How do...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.