none
How to perform QueryInterface in C# RRS feed

  • Question

  • From the text services framework documentation on MSDN,

    The ITfThreadMgrEx interface is used by the application to activate the textservices with some flags. ITfThreadMgrEx can be obtained by QI from ITfThreadMgr .

    My understanding is that in C#, QueryInterface is performed on IUnknown type of interfaces by using the AS key word. So in my code, I perform the following steps.

     

        ITfThreadMgr ThreadMgr;
        ITfThreadMgrEx ThreadMgrEx;
        ThreadMgr = TsfInterfaces.CreateManager();
        ThreadMgrEx = ThreadMgr as ITfThreadMgrEx;

        [Guid("aa80e801-2021-11d2-93e0-0060b067b86e")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        public interface ITfThreadMgr
        {
            ...
        }


        [Guid("3e90ade3-7594-4cb0-bb58-69628f5f458c")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        [ComVisible(true)]
        public interface ITfThreadMgrEx
        {
            ...
        }

    In the code above, I am successful in getting the ThreadMgr, and I can even use it successfully. But what I want to do next requires I obtain the ITfThreadMgrEx interface. However, ThreadMgrEx comes back null from using the AS key word.

    Does anyone know what I am doing wrong here? Any help would be appreciated...

     

    More information... I wrote a quick C++ test code and got back E_NOINTERFACE from the QueryInterface call for ITfThreadMgrEx. I would imagine that this is why ITfThreadMgrEx is coming back null in the C# code, but I really don't understand what is wrong - why this is not working according to Microsoft's documentation. Any help is appreciated.

     

        HRESULT hr = ::CoInitialize(NULL);
        ITfThreadMgr * p = NULL;
        ITfThreadMgrEx * pe = NULL;
        hr = ::CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC, IID_ITfThreadMgr, (void**)&p);
        hr = p->QueryInterface(IID_ITfThreadMgrEx, (void**)&pe);


    Monday, February 7, 2011 10:47 PM

Answers

  • I have the framework working with C# now and my intention is to simply move to windows 7 professional or embedded.
    • Marked as answer by Greg Ofiesh Saturday, July 2, 2011 2:25 AM
    Saturday, July 2, 2011 2:25 AM

All replies

  • There must be something wrong on your system, your code is fine, i ran your C++ sample which returned S_OK on the QI call and got me a valid pointer in pe.

     

     

    Tuesday, February 8, 2011 5:45 PM
  • Was your system XP Pro SP3? The Microsoft documentation states that ITfThreadMgrEx should be available with Windows 2000, but I wonder if this is incorrect, or if as you say there is something wrong with my system.
    Tuesday, February 8, 2011 5:58 PM
  • That was on Vista64, i ran a quick test on XP/SP3 where the CoCreateInstance call  failed with HR= 0x80004005  , then tried getting it using the TF_CreateThreadMgr function, which also returned 0x80004005.  Tinkered with it for a few more minutes but yeah didn't seem too happy, no clue whats up with xp SP3, should work, but doesn't look like it actually does, or at least on my test machine.
    Tuesday, February 8, 2011 6:42 PM
  • I can get the ITfThreadMgr interface once I install the far east languages and add Chinese (PRC) to the language bar (Regional and Language in the control panel). I can get this interface using both approaches you describe.

    But for some reason the interfaces that are QI'd from ITfThreadMgr that are directly related to customizing the UI components of the TIP are not available. I can get other interfaces from ITfThreadMgr.QueryInterface, such as ITfClientId and ITfMessagePump, but I cannot get ITfUIElementMgr nor ITfThreadMgrEx.

    It is like the feature to custom draw the TIP UI is simply not installed or enabled. But I am not certain if that is even the correct direction to look in.

    Tuesday, February 8, 2011 8:53 PM
  • I have the framework working with C# now and my intention is to simply move to windows 7 professional or embedded.
    • Marked as answer by Greg Ofiesh Saturday, July 2, 2011 2:25 AM
    Saturday, July 2, 2011 2:25 AM