Return S_FALSE from C # COM dll

I have a method defined in IDL as follows:

interface IMyFunc : IDispatch
{
    [id(1), helpstring("method GetNextFunction")] HRESULT GetNextFunction(
        [in,out] long* lPos, [out, retval] BSTR* bstrName);
}

Using C ++, I always did this as follows:

STDMETHODIMP CMyFunc::GetNextFunction(long *nID, long *lPos, BSTR *bstrName)
{
    if ( function to return )
    {
        // setup return values;
        return S_OK;
    }
    else
    {
        // just exit
        return S_FALSE;
    }
}

Now I implement this in C # and used tlbimp in the type library and ended up with:

public string GetNextFunction(ref int nID, ref int lPos)

I understand that this is because [out, retval] is used as the return type instead of HRESULT, as in C ++. Is there an easy way to return S_OK / S_FALSE values ​​without changing the method definition? The only way I see is that I have to use ildasm / ilasm to add saveesig so that it ends up with something like this:

public int GetNextFunction(ref int nID, ref int lPos, ref string bstrName)

I was wondering if there is another way without performing the il compilation step.

+3
source share
2 answers

/PreserveSig tlbimp. PreserveSigAttribute , . , . tlbimp CodePlex.

+2

, /PreserveSig, , PreserveSig , .

PreserveSig , COM #, PreserveSig . - TLBIMP , .

+1

Source: https://habr.com/ru/post/1740158/


All Articles