C# and COM interoperability

Posted on 2006-05-02
Last Modified: 2013-11-25

I'm doing this service for my job and I need to code a module that forwards call from a C++ program to a DLL. Normaly, the C++ program instanciate the DLL with his GUID and then calls some functions. I changed the GUID of the DLL and took the original GUID and applied it to my service so now when the C++ program needs a instance of the DLL, it calls me. I then instanciate the good DLL and forward the calls. This works fine until I need the return value of the forwarded call to the DLL. The .NET documentation states that when a call to a COM object fails (HRESULT != S_OK or S_FAIL) the CLR converts this failure by returning an Exception to the callee (my service). The problem is that i know the return value is different from S_OK and S_FAIL but i don't catch the exception ! (with try/catch block)

This problem comes from the fact that the interface I used to communicate with the DLL returns a HRESULT result but has no [out,retval] param so when i use midl to create the tlb and tlbimp to then create the DLL, the resulting interface i can use in my C# project has a VOID signature. And I must read the HRESULT return value for other processing.

How can I get the HRESULT value from my C# code ?
Question by:LeibNiZ
    1 Comment
    LVL 14

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Android App Development

    This course will involve creating widgets, customize list view, grid view, spinners, etc. Creating applications using audio, video, and SQLite database. Ending with publication on Google Play.

    Suggested Solutions

    Title # Comments Views Activity
    format the code in java 6 60
    abstract class with all non abstract mentods 6 58
    FizzBuzz challenge 9 64
    seriesUp challenge 7 81
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now