SpObjectToken GetStorageFileName method

Microsoft Speech SDK

Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

Object: SpObjectToken
Type: Hidden

GetStorageFileName Method


The GetStorageFileName method creates a storage file for data associated with the object token.


SpObjectToken.GetStorageFileName(
     ObjectStorageCLSID As String,
     KeyName As String,
     FileName As String,
     Folder As SpeechTokenShellFolder
) As String

Parameters

ObjectStorageCLSID
Globally unique identifier (GUID) of the calling object. The method searches the registry for an entry key name of ObjectStorageCLSID, and then a corresponding Files subkey. If the registry entry is not present, one is created.
KeyName
The name of the attribute file for the registry entry of clsidCaller. This attribute stores the location of the resource file.
FileName
A specifier that is either "" or a path/file name for storage file.
  • If this starts with "X:\" or "\\" it is assumed to be a full path; otherwise it is assumed to be relative to special folders given in the nFolder parameter.
  • If it ends with a "\", or is NULL, a unique file name will be created. The file name will be something like: "SP_7454901D23334AAF87707147726EC235.dat". "SP_" and ".dat" are the default prefix name and file extension name. The numbers in between are generated guid number to make sure the file name is unique.
  • If the name contains a %d the %d is replaced by a number to give a unique file name. The default file extension is .dat, the user can specify anything else. Intermediate directories are created.
  • If a relative file is used, the value stored in the registry includes the nFolder value as %nFolder% before the rest of the path.
Folder
One or more SpeechTokenShellFolder constants specifying the Folder.

Return Value

A String variable containing the path of the storage file.


Example

The following Visual Basic form code demonstrates the GetStorageFileName and RemoveStorageFileName methods. To run this code, create a form with the following controls:

  • Four command buttons, called Command1, Command2, Command3, and Command4
  • Paste this code into the Declarations section of the form.

    The operations performed in this example can best be viewed with REGEDIT.EXE. For a discussion of Registry issues, please see the ISpeechDataKey interface.

    The Form_Load procedure creates a new SpObjectToken object, and sets its ID property to a new subfolder called Demo within the Voices\Tokens folder. The True parameter of the SetId call forces the creation of this folder, if it does not already exist.

    The Command1 procedure creates a data key object which references the new Demo folder, and uses the data key to write a value into the folder.

    The Command2 procedure calls the GetStorageFileName method. After this call, the Demo folder contains a subfolder called {CDD1141B-82FB-405c-99BE-69A793A92D87}. This is the CLSID used as a parameter of the GetStorageFileName method. Within this is a folder called Files, which contains a the storage file path in a value called Demo.

    The Command3 procedure calls the RemoveStorageFileName method. This deletes the storage file, and removes the Demo value from the Files folder.

    The Command4 procedure uses the ISpeechDataKey.Remove method to delete the {CDD1141B-82FB-405c-99BE-69A793A92D87} folder and Demo folders.


    Option Explicit
    
    Dim T As SpeechLib.SpObjectToken            'one object token
    Dim C As SpeechLib.SpObjectTokenCategory    'one object token category
    Dim K As SpeechLib.ISpeechDataKey           '
    Dim ID As String
    Dim SF As String                            'Storage file name
    Dim TestCLSID As String
    
    Private Sub Command1_Click()
    
        'Set data key object to the demo voice's folder,
        'Write a CLSID value
        Set K = T.DataKey
        K.SetStringValue "CLSID", TestCLSID
        
    End Sub
    
    Private Sub Command2_Click()
    
        'Create a storage file for the token
        SF = T.GetStorageFileName(TestCLSID, "Demo", vbNullString, _
                                  STSF_FlagCreate + STSF_AppData)
        MsgBox SF
    
    End Sub
    
    Private Sub Command3_Click()
    
        'Remove the storage file
        Call T.RemoveStorageFileName(TestCLSID, "Demo", True)
    
    End Sub
    
    Private Sub Command4_Click()
    
        'Remove the "{CDD1141B-82FB-405c-99BE-69A793A92D87}" folder,
        'and the "Demo" folder
        T.Remove TestCLSID
        T.Remove ""
    
    End Sub
    
    Private Sub Form_Load()
    
        TestCLSID = "{CDD1141B-82FB-405c-99BE-69A793A92D87}"
    
        'Create new category object, set it to Voices category
        Set C = New SpObjectTokenCategory
        C.SetId SpeechCategoryVoices
        
        'Create new token object, and set its ID
        'to the path of a folder which does not exist
        '"True" parameter creates the folder
        
        Set T = New SpObjectToken
        ID = SpeechCategoryVoices & "\Tokens\Demo"
        T.SetId ID, , True
        
    End Sub