Solved

Getting instance of an extended interface to use base interface functions

Posted on 2008-10-29
4
898 Views
Last Modified: 2010-04-21
I have been working with Microsoft's Speech API 5.1, and now need to use the extended functionality in SAPI 5.3.  In SAPI 5.3, the new Interface ISpRecognizer2 extends ISpRecognizer from SAPI 5.1.  Now I create an instance of an ISpRecognizer2 and it works fine for the extended functions such as SetTrainingState(). But when I try to execute functions such as SetInput() that are in ISpRecognizer, I get the error "'SetInput' : is not a member of 'ATL::_NoAddRefReleaseOnCComPtr<T>' with [  T=ISpRecognizer2  ].

I'm a relative novice to C++, but have used Java and Smalltalk for decades, and it has always been true that a class or interface extending another one inherits all the functions of the base class. I know that C++ Interfaces are a bit of a workaround, but don't understand how to create an instance of the extended interface that executes functions from both levels of interface. I'm sure it's simple, but I haven't found any documentation.

The SAPI 5.3 is at http://msdn.microsoft.com/en-us/library/ms720424(VS.85).aspx
The code snippet shows the creation and cases of methods that work and don't.

Thanks for the help!
#include <sapi.h>
 

CComPtr<ISpRecognizer2> cpRecognizer;
 

cpRecognizer.CoCreateInstance(CLSID_SpInprocRecognizer);
 

cpRecognizer->SetTrainingState(TRUE, TRUE);//THIS FROM EXTENDED INTERFACE WORKS
 

cpRecognizer->SetInput(cpStream, TRUE);//THIS FROM BASE INTERFACE GETS ERROR

Open in new window

0
Comment
Question by:hutch100
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:romanm
Comment Utility
looks like it does not inherit from ISpRecognizer, so you need to QueryInterface to get ISpRecognizer,

// should do the trick. CComPtr copy constructor will do the QueryInterface for you.
CComPtr<ISpRecognizer> cpRecognizerBase = cpRecognizer;
// now we can use base functions
cpRecognizerBase->SetInput(cpStream, TRUE);
0
 

Author Comment

by:hutch100
Comment Utility
I looked at the sapi.h (part of Windows SDK now) and it does seem that the 2 interfaces are defined independently, despite the API saying that one extends the other (and it should, to be useful). Yet both can be constructed with the same line:
cpRecognizer.CoCreateInstance(CLSID_SpInprocRecognizer).

I tried your suggestion and got the following error:

error C2440: 'initializing' : cannot convert from 'ATL::CComPtr<T>' to 'ATL::CComPtr<T>'
        with     [  T=ISpRecognizer2    ]
        and      [  T=ISpRecognizer      ]
 No constructor could take the source type, or constructor overload resolution was ambiguous

Might it work to copy the functions I need in the sapi files? Or other idea? Thanks!
0
 
LVL 3

Accepted Solution

by:
romanm earned 500 total points
Comment Utility
Try,
CComPtr<ISpRecognizer> cpRecognizerBase;
cpRecognizer.QueryInterface<ISpRecognizer>(&cpRecognizerBase);

I am assuming you are using ATL::CComPtr.
0
 

Author Closing Comment

by:hutch100
Comment Utility
That was brilliant!  Microsoft erred in not making it a subinterface as their doc claimed (which I confirmed by changing the .h file and getting it to compile but of course still a runtime error), but without source code I couldn't fix it.  Please accept my gratitude for saving me a lot of trouble and delay!!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 clear a vector as well as how to detect empty vectors in C++.

772 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

11 Experts available now in Live!

Get 1:1 Help Now