Last reviewed: 7/27/2024 8:16:33 AM

Microsoft Visual C++ Applications

Develop C++ applications that manage grammars using your favorite version of Microsoft Visual C++.

The following sections describe the steps for integrating GrammarKit with Microsoft Visual C++ applications.

GrammarKit Header Files

GrammarKit includes C++ header files comprised of the C++ classes that manage grammars and automatically load and unload the runtime DLL.

To access GrammarKit C++ classes within a Visual C++ application, add project references to the following nuget packages:

  • Select the application project in the Solution Explorer.
  • Right-click the mouse and select the Manage Nuget Packages… menu item.
  • Enter Chant in the search bar.
  • Select the Chant.GrammarKit.Windows package and press the Install button.
  • Chant GrammarKit Windows package
  • Select the Chant.Shared.Windows package and press the Install button.
  • Chant Shared Windows package

To access the GrammarKit C++ classes within your application, add a reference to the Chant shared and GrammarKit header files in your C++ application header file:


#include "Chant.Shared.Windows.h"
#include "Chant.GrammarKit.Windows.h"

Add a reference in your C++ application source file to the Chant shared and GrammarKit code needed to dynamically load and unload the runtime DLL:


#include "Chant.Shared.Windows.cpp"
#include "Chant.GrammarKit.Windows.cpp"

Object Instantiation

Declare a global variable for the GrammarKit class, instantiate instance, set the credentials, and set the event handler message.

Add the following to your application header file:


    protected:
    CGrammarKit* _GrammarKit;
    CSAPI5Recognizer* _Recognizer;
};

Add the following to your application source file:


// Instantiate GrammarKit object
_GrammarKit = new CGrammarKit();

if (_GrammarKit =! NULL)
{
    // Set credentials
    _GrammarKit->SetCredentials(L"Credentials");
    // Create recognizer
    _Recognizer = _GrammarKit->CreateSAPI5Recognizer();
    if (_Recognizer != NULL)
    {
        // Register Event Handlers
        _Recognizer->SetCompileDone(CompileDone);
        _Recognizer->SetCompileError(CompileError);
    }
}

GrammarKit applications require the GrammarKit library (CGrammarKit.dll or CGrammarKitX64.dll) and the applicable GrammarKit Speech API library in the same directory as the application .exe.

Speech APsI GrammarKit Speech API class GrammarKit Speech API library
Microsoft SAPI 5CSAPI5RecognizerCGrammarKit.SAPI5.dll or CGrammarKitX64.SAPI5.dll
Microsoft Speech PlatformCMSPRecognizerCGrammarKit.MSP.dll or CGrammarKitX64.MSP.dll
Microsoft WindowsMediaCWindowsMediaRecognizerCGrammarKit.WinRT.dll or CGrammarKitX64.WinRT.dll

Event Callbacks

Event callbacks are the mechanism in which the class object sends information back to the application such as compilation is complete or there was an error.


void CALLBACK CompileDone(void* Sender, CCompileEventArgs* Args)
{
    ...
}
void CALLBACK CompileError(void* Sender, CCompileEventArgs* Args)
{
    // Format transcript message
    CString strErrorMsg;
    strErrorMsg.Format(L"(%d) error %d %s\r\n", Args->GetError(), Args->GetLineNumber(), Args->GetDescription());
    ...
}

Development and Deployment Checklist

When developing and deploying C++ applications, ensure you have a valid license, bundle the correct Chant class library, and configure your installation properly on the target system. Review the following checklist before developing and deploying your applications:

  • Develop and deploy C++ applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
  • Copy CGrammarKit.dll to the target system and place in the same directory with your application.
  • Copy applicable 32-bit Speech API DLL(s) to the target system and place in the same directory with your application.
  • Develop and deploy C++ applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
  • Copy CGrammarKitX64.dll to the target system and place in the same directory with your application.
  • Copy applicable 64-bit GrammarKit Speech API DLL(s) to the target system and place in the same directory with your application.

Sample Projects

Microsoft Visual C++ sample projects that use nuget packages may be found in the following directory of the vssamples.zip download:

  • Chant\GrammarKit 10\CDLL.