Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6024655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:11:14+00:00 2026-05-23T04:11:14+00:00

(preliminary note: I’m not yet fully up to speed with the whole ‘interop’ thing…)

  • 0

(preliminary note: I’m not yet fully up to speed with the whole ‘interop’ thing…)

When using a COM library from within .NET, all HRESULT methods are wrapped into something that throws when the return code is not SUCCEEDED.

//ATL magic exluded
class C {
    HRESULT foo(){ return E_FAIL; }
};

// usage code:
if( SUCCEEDED( c.foo() ) ) {
   // success code
} else {
   // failure code
}

The .NET counterpart of this code reads:

try {
   c.foo();
   // success code
} catch ( Exception e ) {
   // failure code
}

Is there a way to access the COM return code directly in .NET, so that no exception handling is needed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:11:14+00:00Added an answer on May 23, 2026 at 4:11 am

    Yes, but you’ll have to manually define the interop interface (rather than use tlbimp.exe) and use the PreserveSig attribute on the methods in question.

    For example:

    [ComImport]
    [Guid("your-guid-here")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    interface IMyComInterface
    {
         [PreserveSig]
         int DoSomething(out int result);
    }
    

    That is the equivalent of a COM method with the signature HRESULT DoSomething([out, retval] int *result);

    If your interface is very complicated or you get stuck on how to define the interop interface, I recommend using tlbimp.exe, then using Reflector or ILSpy or something similar to decompile the generated interfaces, and then edit those to your liking. Saves work, too. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in the preliminary stages of designing a new web application, and have yet
I am using Eclipse with Java 1.6. I was wondering what the preliminary steps
Preliminary : I have an application which maintains a thread pool of about 100
I want to do preliminary check if entered string looks like Vehicle Identification Number
From a couple of preliminary tests it seems that EnumWindows always returns windows in
I have a short preliminary interview with Microsoft in less than 2 hours. I've
I am in the preliminary stages of planning a project with a client to
Sorry for bad English :( Suppose i can preliminary organize recipes and ingredients data
So, I've got a single VB6 executable that references multiple VB6 COM DLLs. Is
Preliminary: I am writting my own httpclient in Java. I am trying to parse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.