locked
Converting C++ com interface to C# - ISearchBoxInfo RRS feed

  • Question

  • Hello, I'm trying to convert the ISearchBoxInfo into C#.

    This is related to my namespace extension project:

    basically, i've queried the interface using "SetSite" method

    var serviceProv = Marshal.GetObjectForIUnknown(m_pUnkSite) as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
    
    
    IntPtr ptr;
    int rc = serviceProv.QueryService(ref searchBoxGUID, ref searchBoxInterfaceGUID, out ptr);
    boxInfo = Marshal.GetObjectForIUnknown(ptr) as ISearchBoxInfo;
    

    Everything works fine, no errors.

    when i'm trying to call the methods, i get rc of 0x80004002 (which is E_NOINTERFACE).

    the C++ interface looks like that:

    MIDL_INTERFACE("6af6e03f-d664-4ef4-9626-f7e0ed36755e")
        ISearchBoxInfo : public IUnknown
        {
        public:
            virtual HRESULT STDMETHODCALLTYPE GetCondition(
                /* [in] */ __RPC__in REFIID riid,
                /* [iid_is][out] */ __RPC__deref_out_opt void** ppv) = 0;
            
            virtual HRESULT STDMETHODCALLTYPE GetText(
                /* [string][out] */ __RPC__deref_out_opt_string LPWSTR *ppsz) = 0;
            
        };
     

    i've converted that to:

    [ComImport(),
          Guid(IIDGuid.ISearchBoxInfo),
          InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            internal interface ISearchBoxInfo
            {
                [PreserveSig]
                int GetCondition([In] ref Guid riid, out IntPtr ppv);
    
                [PreserveSig]
                int GetText(out IntPtr ppsz);
            }

    i've tried also changing the GetText to ref, or string.

    any help would be appreciated.


    • Moved by CoolDadTx Tuesday, February 6, 2018 3:27 PM Extensibility related
    Tuesday, February 6, 2018 12:37 PM

All replies

  • Hi Ariel135,

    You could interop your C++ com interface, which does not need to convert to c# interface.  For more information, please refer to:

    https://msdn.microsoft.com/en-us/library/ms973872.aspx

    In addition, about Building COM Objects in C#, please refer to:

    https://www.codeproject.com/Articles/7859/Building-COM-Objects-in-C

    about get E_NOINTERFACE when creating an object.

    https://blogs.msdn.microsoft.com/oldnewthing/20041213-00/?p=37043

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 7, 2018 6:41 AM
  • I've already tried it also in C++ - the same problem arises..

    the object is created well, but the usage returns E_NOINTERFACE

    Wednesday, February 7, 2018 8:26 AM
  • Hi Ariel135,

    >>the object is created well, but the usage returns E_NOINTERFACE

    Maybe you pass the wrong argument. and the following similar issue for your reference.

    https://stackoverflow.com/questions/935768/c-sharp-wrapper-interface-error-e-nointerface

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 8, 2018 5:34 AM
  • Hi, nope - this was not the issue.

    Apparently - when the SearchBox contains no value at all - it always return E_NOINTERFACE, when there's a value there - it returns the correct string.

    Sadly the SetSite is not an option here because the methods i'm interested of checking the searchbox (EnumObjects) runs on a different thread, so i lose the pUnknown and the whole com interface..

    • Marked as answer by Ariel135 Thursday, February 8, 2018 8:35 AM
    • Edited by Ariel135 Thursday, February 8, 2018 8:36 AM
    • Unmarked as answer by Ariel135 Thursday, February 8, 2018 8:36 AM
    Thursday, February 8, 2018 8:35 AM
  • Hi Ariel135,

    From the following blog, if your threading model is incompatible with the threading model of the object you're creating, then COM marshalling kicks in. And if the marshalling stuff isn't there, the error that comes out is E_NOINTERFACE, because the marshalling interface is missing.

    https://blogs.msdn.microsoft.com/oldnewthing/20041213-00/?p=37043

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 27, 2018 5:17 AM