COMatePLUS version 1.2

Developed or developing a new product in PureBasic? Tell the world about it.
sec
Enthusiast
Enthusiast
Posts: 789
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Re: COMatePLUS version 1.2

Post by sec »

With last beta 4.20 beta 9: i got this error, how fix?
at this line:

Code: Select all

 Procedure.i COMate_INTERNAL_PrepareStatement(command$, *ptrStatement.INTEGER)
...
errorCode = COMatePLUS_CompileSubobjectInvokation(*hStatement, subObject, @parse()) ;<-- Error: [Compiler] Bad parameter type: an arrary is expeced 
....

Thanks
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: COMatePLUS version 1.2

Post by srod »

Remove the @.
I may look like a mule, but I'm not a complete ass.
sec
Enthusiast
Enthusiast
Posts: 789
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Re: COMatePLUS version 1.2

Post by sec »

srod wrote:Remove the @.
Thanks you :)
User avatar
Frontier
User
User
Posts: 74
Joined: Thu Dec 22, 2005 2:43 pm
Location: Chios, Greece
Contact:

Re: COMatePLUS version 1.2

Post by Frontier »

Hello,

I am using this excellent library to write a small command line utility that will use several COM objects of a large ERP application.
I have trouble passing a COMateObject object as a parameter.

Here is the object in question (using Microsoft OLE/COM Object Viewer) - CLSID: {4163F5AF-7147-11D5-A90D-009027A25409}.
The method of interest is LoadFromXMLFile().

Code: Select all

// Generated .IDL file (by the OLE/COM Object Viewer)
// 
// typelib filename: ImportProfiles.dll

[
  uuid(4163F59A-7147-11D5-A90D-009027A25409),
  version(3.32),
  custom(50867B00-BB69-11D0-A8FF-00A0C9110059, 8964)

]
library ImportProfiles
{
    // TLib :     // TLib : File Parser : {19500CE0-E9F9-11D3-BA2B-00A0C9A55947}
    importlib("FileParser.dll");
    // TLib : Microsoft ActiveX Data Objects 2.1 Library : {00000201-0000-0010-8000-00AA006D2EA4}
    importlib("msado21.tlb");
    // TLib : CLDLogic 2.0 Type Library : {AE6E1F4C-7245-11D3-8618-00A0C9A55A3E}
    importlib("CLDLogic.dll");
    // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("stdole2.tlb");
    // TLib : Microsoft XML, v3.0 : {F5078F18-C551-11D3-89B9-0000F81FE221}
    importlib("msxml3.dll");
    // TLib : Visual Basic For Applications : {000204EF-0000-0000-C000-000000000046}
    importlib("msvbvm60.dll");

    // Forward declare all types defined in this typelib
    interface _ClassFactory;
    interface _ImportProfile;
    interface _IASCIISource;
    interface _IERPSource;
    interface _IRDBMSSource;
    interface _Editor;
    interface _Profiles;
    interface _ConnectionAttr;
    interface _ConnectionAttrs;
    interface _IConnectionData;
    interface _CFieldMapping;
    interface _CFieldMappings;
    interface _CLookUpFilter;
    interface _CLookUpFilters;
    interface _CRecordType;
    interface _CRecordTypes;
    interface _CLookUpInfo;
    interface _CWorkFlow;
    interface _CWFStep;
    interface _CSelectFieldsDialog;
    dispinterface __ConnectionAttrs;

    [
      odl,
      uuid(4D2875B6-A113-11D5-A931-009027A25409),
      version(1.0),
      hidden,
      dual,
      nonextensible,
      oleautomation
    ]
    interface _ClassFactory : IDispatch {
        [id(0x60030000)]
        HRESULT LoadFromXML(
                        [in, out] ICLASession** CLSession, 
                        [in, out] IDispatch** pXMLNode, 
                        [out, retval] _ImportProfile** );
        [id(0x60030001)]
        HRESULT MakeXMLNode(
                        [in, out] ICLASession** CLSession, 
                        [in, out] _ImportProfile** pProfile, 
                        [in, out, optional] IDispatch** pXMLRootNode, 
                        [out, retval] IDispatch** );
        [id(0x60030002)]
        HRESULT LoadFromXMLFile(
                        [in, out] ICLASession** CLSession, 
                        [in] BSTR FileName, 
                        [out, retval] _ImportProfile** );
        [id(0x60030003)]
        HRESULT LoadProfilesFromXML(
                        [in, out] ICLASession** CLSession, 
                        [in, out] IDispatch** pxmlRoot, 
                        [out, retval] _Profiles** );
        [id(0x60030004)]
        HRESULT LoadProfilesFromXMLFile(
                        [in, out] ICLASession** CLSession, 
                        [in] BSTR FileName, 
                        [out, retval] _Profiles** );
    };

... (more stuff)
The LoadProfilesFromXML requires an ICLASession** object as argument and returns a _Profiles** object.
I am using the following PB code where in bold is the line with error:

Code: Select all

XIncludeFile "COMatePlus.pbi"

Define.COMateObject clApp, clSess, clProf, clProfFact

clApp=comate_createobject("Commercial.CLApplication")

If clApp
	MessageRequester("Info","Object created for App")
	
	clSess=clApp\GetObjectProperty("CLSession") ; try to get session interface
	If clSess
		MessageRequester("Info","Session Created")
		
		; Invoke the Login() method from CLSession
		clSess\Invoke("Login('LDD' AS BSTR,'1/1/13' AS BSTR,'clroot' AS BSTR,'clroot' AS BSTR)")
		MessageRequester("Info","Message "+Str(COMate_GetLastErrorCode())+" "+COMate_GetLastErrorDescription())
		MessageRequester("User Name",clSess\GetStringProperty("UserName()"))
	
		; Create a Import Profile Factory object
		clProfFact=COMate_CreateObject("{4163F5AF-7147-11D5-A90D-009027A25409}")
		MessageRequester("Info2", "classFactory "+Str(COMate_GetLastErrorCode())+" "+COMate_GetLastErrorDescription())
		
		hStatement=COMate_PrepareStatement("LoadFromXMLFile(clSess AS COMateObject, 'C:\Temp\ms-ImportData.xml' AS BSTR)")
		clProf = clProfFact\GetObjectProperty("",hStatement)
		
		MessageRequester("Info3", "Profile object "+Str(COMate_GetLastErrorCode())+" "+COMate_GetLastErrorDescription())
	Else
		MessageRequester("Sess","Failed to create session "+Str(COMate_GetLastErrorCode())+" "+COMate_GetLastErrorDescription())
	EndIf
Else
	MessageRequester("Info","Can't create app object")
	MessageRequester("Info",Str(comate_getlasterrorcode())+"  "+comate_getlasterrordescription())
EndIf
End
The error returned: Profile object -(some number) One or more arguments are invalid. Possibly a numerical overflow or too many nested objects, -if so try splitting your method call into two or more subcalls.

The only object I am trying to pass is clSess but I am afraid I'm either doing something terribly wrong preparing the statement or the LoadFromXMLFile() is used incorrectly.

Is there an example that covers this case?

Thank you very much in advance.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: COMatePLUS version 1.2

Post by srod »

Change

Code: Select all

hStatement=COMate_PrepareStatement("LoadFromXMLFile(clSess AS COMateObject, 'C:\Temp\ms-ImportData.xml' AS BSTR)")
to something like :

Code: Select all

hStatement=COMate_PrepareStatement("LoadFromXMLFile(" + Str(clSess) + " AS COMateObject, 'C:\Temp\ms-ImportData.xml' AS BSTR)")
(You don't need the "AS BSTR" either! :) )
I may look like a mule, but I'm not a complete ass.
sec
Enthusiast
Enthusiast
Posts: 789
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Re: COMatePLUS version 1.2

Post by sec »

Could you please upload update version for pb 5.2x?
Thanks.
User avatar
Frontier
User
User
Posts: 74
Joined: Thu Dec 22, 2005 2:43 pm
Location: Chios, Greece
Contact:

Re: COMatePLUS version 1.2

Post by Frontier »

sec wrote:Could you please upload update version for pb 5.2x?
Thanks.
Just follow the advice here, it works: http://www.purebasic.fr/english/viewtop ... 85#p420871
sec
Enthusiast
Enthusiast
Posts: 789
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Re: COMatePLUS version 1.2

Post by sec »

Frontier wrote:
sec wrote:Could you please upload update version for pb 5.2x?
Thanks.
Just follow the advice here, it works: http://www.purebasic.fr/english/viewtop ... 85#p420871
I know that, but i want one offical release for PB 5.2x 8)
Liqu
User
User
Posts: 77
Joined: Sun Apr 21, 2013 10:31 am

Re: COMatePLUS version 1.2

Post by Liqu »

Hi, i'm trying to use SAPI 5.1 code from : http://www.purebasic.fr/english/viewtop ... 12&t=51489
but i get unknown error :
Unknown error. (Code : Hex 80045003). Please report this error code to the author at 'enquiries@nxsoftware.com'

Please help, thank you :)

Code: Select all

XIncludeFile "COMatePLUS.pbi"

;{- Enumerations / DataSections
;{ Windows
Enumeration
  #Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
  #Text_Message
  #String
  #Text_2
  #Text_3
  #Editor
  #Button_Desactive
  #Button_Reactive
EndEnumeration
;}
;{ Fonts
Enumeration
  #Font_Text_Message
  #Font_String_1
EndEnumeration
;}
;}

Structure Parametres
  SpRecoContext.i
  SpeechRecoGrammar.i
EndStructure

Procedure SpeechRecoContextEvents(event.COMateObject, event$, parameterCount)
  Protected iParam.iUnknown
  Protected SpeechRecoResult.COMateObject
  Protected SpeechPhraseInfo.COMateObject
  Protected SpeechPhraseElements.COMateObject
  Protected SpeechPhraseElement.COMateObject
  Protected SpeechPhraseRule.COMateObject
  Protected Texte.s, Word.s
  Protected count.l, niveau.l, a.l
 
  ; Debug("EVT " + Str(parameterCount) + " " + event$)
 
  Select event$
    Case "FalseRecognition"
      SetGadgetText(#String, "<Unrecognized word or phrase>")
     
    Case "Recognition"
      Debug "-------------Recognition-----------------"
      iParam = event\GetObjectEventParam(4)
      If iParam
        SpeechRecoResult = COMate_WrapCOMObject(iParam)
       
        If SpeechRecoResult
          SpeechPhraseInfo = SpeechRecoResult\GetObjectProperty("PhraseInfo()")
          COMate_GetLastErrorDescription()
          If SpeechPhraseInfo
           
            Texte = SpeechPhraseInfo\GetStringProperty("GetText(0, -1, 1)")
            SetGadgetText(#String, Texte)
           
            SpeechPhraseElements = SpeechPhraseInfo\GetObjectProperty("Elements")
            If SpeechPhraseElements <> 0
              count = SpeechPhraseElements\GetIntegerProperty("Count")
              For a = 0 To count - 1
                SpeechPhraseElement = SpeechPhraseElements\GetObjectProperty("Item(" + Str(a) + ")")
                If SpeechPhraseElement <> 0
                  niveau = SpeechPhraseElement\GetIntegerProperty("ActualConfidence")
                  ; #SECLowConfidence = -1    ; niveau de reconnaissance basse
                  ; #SECNormalConfidence = 0  ; niveau de reconnaissance normal
                  ; #SECHighConfidence = 1    ; niveau de reconnaissance haute
                  ; Pour chaque mot, j'affiche le niveau de reconnaissance
                  Word = SpeechPhraseElement\getstringproperty("DisplayText")
                  Debug "Word = "+Word+" ; Niveau = " + Str(niveau)
                  SpeechPhraseElement\Release()
                EndIf
              Next a
             
              SpeechPhraseElements\Release()
            EndIf
           
            SpeechPhraseRule = SpeechPhraseInfo\GetObjectProperty("Rule")
            If SpeechPhraseRule <> 0
              rule.s = SpeechPhraseRule\GetStringProperty("Name")
              Debug "Rule = " + rule
              SpeechPhraseRule\Release()
            EndIf
           
           
            Select Rule
              Case "show"
                MessageRequester("Info", "Command = " + Rule)
              Case "hide"
                MessageRequester("Info", "Command = " + Rule)
            EndSelect
           
            SpeechPhraseInfo\Release()
          EndIf
          SpeechRecoResult\Release()
        EndIf
        iParam\Release()
      EndIf
     
    Case "Hypothesis"
      Debug "------------Hypothesis------------------"
     
      SetGadgetText(#Text_Message, "Analysis ongoing...")
     
      iParam = event\GetObjectEventParam(3)
      If iParam
        SpeechRecoResult = COMate_WrapCOMObject(iParam)
        If SpeechRecoResult
          SpeechPhraseInfo = SpeechRecoResult\GetObjectProperty("PhraseInfo()")
          If SpeechPhraseInfo
           
            Texte = SpeechPhraseInfo\GetStringProperty("GetText(0, -1, 1)")
           
            SetGadgetText(#Editor, Texte + Chr(13) + GetGadgetText(#Editor))
           
            SpeechPhraseInfo\Release()
          EndIf
          SpeechRecoResult\Release()
        EndIf
        iParam\Release()
      EndIf
     
    Case "SoundStart"
      Debug "SoundStart"
      SetGadgetText(#String, "")
     
    Case "SoundEnd"
      Debug "SoundEnd"
      SetGadgetText(#Text_Message, "Speak")
     
    Case "StartStream"
      ; Debug "StartStream"
     
    Case "EndStream"
      ; Debug "EndStream"
     
  EndSelect
EndProcedure

Procedure Load_Speech_Recognition(*Speech_Recognition.Parametres, File.s)
  Protected SpRecoContext.COMateObject
  Protected SpRecoGrammar.COMateObject
  Protected Init_Recognition.l = 0
 
  Protected SpRecognizer.COMateObject
  Protected SpeechRecognizer.COMateObject
  Protected SpObjectTokenCategory.COMateObject
  Protected SpObjectToken.COMateObject
 
 
  SpRecoContext = COMate_CreateObject("SAPI.SpInProcRecoContext")
  Debug COMate_GetLastErrorDescription()
  If SpRecoContext = 0 : Goto Clean : EndIf
 
 
  SpRecoGrammar = SpRecoContext\GetObjectProperty("CreateGrammar(0)")
  If SpRecoGrammar = 0 : Goto Clean : EndIf
 
  RecoGrammar.idispatch = SpRecoGrammar\GetCOMObject()
  If RecoGrammar = 0 : Goto Clean : EndIf
 
  RecoGrammar\QueryInterface(?IID_ISpeechRecoGrammar, @SpeechRecoGrammar_)
  If SpeechRecoGrammar_ = 0 : Goto Clean : EndIf
  SpRecoGrammar\Release()
 
  SpeechRecoGrammar.COMateObject = COMate_WrapCOMObject(SpeechRecoGrammar_)
  If SpeechRecoGrammar = 0 : Goto Clean : EndIf
 
  #SLOStatic = 0
  #SLODynamic = 1
  If SpeechRecoGrammar\invoke("CmdLoadFromFile('" + File + "', " + Str(#SLODynamic) + ")") <> 0
    Goto Clean
  EndIf
 
  If SpRecoContext\SetEventHandler(#COMate_CatchAllEvents, @SpeechRecoContextEvents()) <> 0
    Goto Clean
  EndIf
 
  SpRecognizer = SpRecoContext\GetObjectProperty("Recognizer()")
  If SpRecognizer = 0 : Goto Clean : EndIf
 
  Recognizer.idispatch = SpRecognizer\GetCOMObject()
  If Recognizer = 0 : Goto Clean : EndIf
 
  Recognizer\QueryInterface(?IID_ISpeechRecognizer, @SpeechRecognizer_)
  If SpeechRecognizer_ = 0 : Goto Clean : EndIf
 
  SpeechRecognizer.COMateObject = COMate_WrapCOMObject(SpeechRecognizer_)
  If SpeechRecognizer = 0 : Goto Clean : EndIf
 
  SpObjectTokenCategory = COMate_CreateObject("SAPI.SpObjectTokenCategory")
  If SpObjectTokenCategory = 0 : Goto Clean : EndIf
 
  #SpeechCategoryAudioIn = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\AudioInput"
  If SpObjectTokenCategory\invoke("SetId('" + #SpeechCategoryAudioIn + "', 0)") <> 0
    Goto Clean
  EndIf
 
  SpObjectToken = COMate_CreateObject("SAPI.SpObjectToken")
  If SpObjectToken = 0 : Goto Clean : EndIf
 
  Audio$ = SpObjectTokenCategory\GetStringProperty("Default()")
  Debug audio$
  If SpObjectToken\invoke("SetId('" + Audio$ + "')") <> 0
    Goto Clean
  EndIf
 
  If SpeechRecognizer\Setpropertyref("AudioInput(" + Str(SpObjectToken) + " as COMateObject)") <> 0
    Goto Clean
  EndIf
 
  ; La Règle de grammaire est active.
  #SGDSActive = 1
  If SpeechRecoGrammar\invoke("CmdSetRuleIdState(0, " + Str(#SGDSActive) + ")") <> 0
    Goto Clean
  Else
    Init_Recognition = 1
  EndIf
 
  Clean:
  If Init_Recognition = 0
    If SpRecoContext <> 0 : SpRecoContext\Release() : EndIf
    If SpRecoGrammar <> 0 : SpRecoGrammar\Release() : EndIf
    If SpeechRecoGrammar <> 0 : SpeechRecoGrammar\Release() : EndIf
  Else
    *Speech_Recognition\SpRecoContext = SpRecoContext
    *Speech_Recognition\SpeechRecoGrammar = SpeechRecoGrammar
  EndIf
 
  ProcedureReturn Init_Recognition
EndProcedure

Procedure Finish_Speech_Recognition(*Speech_Recognition.Parametres)
  Protected SpRecoContext.COMateObject
  Protected SpeechRecoGrammar.COMateObject
 
  SpRecoContext = *Speech_Recognition\SpRecoContext
  SpeechRecoGrammar = *Speech_Recognition\SpeechRecoGrammar
 
  If SpeechRecoGrammar <> 0
    ; La Règle de grammaire est inactive.
    #SGDSInActive = 0
    SpeechRecoGrammar\invoke("CmdSetRuleIdState(0, " + Str(#SGDSInActive) + ")")
    SpeechRecoGrammar\Release()
  EndIf
 
  If SpRecoContext <> 0
    SpRecoContext\SetEventHandler(#COMate_CatchAllEvents, 0)
    SpRecoContext\Release()
  EndIf
 
EndProcedure

Procedure Desactive_Recognition(*Speech_Recognition.Parametres, Valeur.l)
  Protected SpeechRecoGrammar.COMateObject
  SpeechRecoGrammar = *Speech_Recognition\SpeechRecoGrammar
 
  #SGDSInActive = 0
  #SGDSActive = 1
  If Valeur = 0
    SpeechRecoGrammar\invoke("CmdSetRuleIdState(0, " + Str(#SGDSActive) + ")")
    Debug COMate_GetLastErrorDescription()
  ElseIf Valeur = 1
    SpeechRecoGrammar\invoke("CmdSetRuleIdState(0, " + Str(#SGDSInActive) + ")")
    Debug COMate_GetLastErrorDescription()
  EndIf
 
EndProcedure

Procedure OpenWindow_Window_0()
  If OpenWindow(#Window_0, 732, 260, 600, 400, "Speech Recognition Control and Command", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar | #PB_Window_SizeGadget)
    TextGadget(#Text_Message, 0, 0, 600, 50, "Speak and say : hide or show", #PB_Text_Center)
    StringGadget(#String, 0, 95, 600, 35, "", #PB_String_ReadOnly)
    TextGadget(#Text_2, 0, 75, 600, 20, "  Recognized sentence:")
    TextGadget(#Text_3, 0, 160, 600, 20, "  Hypothetical sentence:")
    EditorGadget(#Editor, 0, 180, 600, 165, #PB_Editor_ReadOnly)
    ButtonGadget(#Button_Desactive, 60, 355, 200, 35, "Deactivate")
    ButtonGadget(#Button_Reactive, 335, 355, 200, 35, "Activate")
    DisableGadget(#Button_Reactive, 1)
    ; Gadget Fonts
    SetGadgetFont(#Text_Message, LoadFont(#Font_Text_Message, "Microsoft Sans Serif", 12, 272))
    SetGadgetFont(#String, LoadFont(#Font_String_1, "Microsoft Sans Serif", 12, 16))
  EndIf
EndProcedure

CoInitialize_(0)

File.s = "sol.xml"           ;put xml file path of "sol.xml"
If Load_Speech_Recognition(@Speech_Recognition.Parametres, File) = 0
  MessageRequester("Erreur", "Initialization of motor speech recognition failed!")
  End
EndIf

OpenWindow_Window_0()

;{- Event loop
Repeat
  Select WaitWindowEvent()
      ;/ //////////////////
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button_Desactive
          DisableGadget(#Button_Reactive, 0)
          DisableGadget(#Button_Desactive, 1)
          Desactive_Recognition(@Speech_Recognition.Parametres, 1)
         
        Case #Button_Reactive
          DisableGadget(#Button_Reactive, 1)
          DisableGadget(#Button_Desactive, 0)
          Desactive_Recognition(@Speech_Recognition.Parametres, 0)
         
      EndSelect
      ;/ ///////////////////////
    Case #PB_Event_CloseWindow
      Select EventWindow()
        Case #Window_0
          CloseWindow(#Window_0)
          Finish_Speech_Recognition(@Speech_Recognition.Parametres)
          CoUninitialize_()
          Break
      EndSelect
  EndSelect
ForEver

;}


Macro GUID(iid, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, b0)
  DataSection
    IID:
    Data.l $a0
    Data.w $a1, $a2
    Data.b $a3, $a4, $a5, $a6, $a7, $a8, $a9, $b0
  EndDataSection
EndMacro

GUID(IID_ISpeechRecoGrammar, B6D6F79F, 2158, 4E50, B5, BC, 9A, 9C, CD, 85, 2A, 09)
GUID(IID_ISpeechRecognizer, 2D5F1C0C, BD75, 4B08, 94, 78, 3B, 11, FE, A2, 58, 6C)
GUID(IID_ISpeechXMLRecoResult, AAEC54AF, 8F85, 4924, 94, 4D, B7, 9D, 39, D7, 2E, 19)

User avatar
leonhardt
Enthusiast
Enthusiast
Posts: 220
Joined: Wed Dec 23, 2009 3:26 pm

Re: COMatePLUS version 1.2

Post by leonhardt »

Liqu wrote:Hi, i'm trying to use SAPI 5.1 code from : http://www.purebasic.fr/english/viewtop ... 12&t=51489
but i get unknown error :
Unknown error. (Code : Hex 80045003). Please report this error code to the author at 'enquiries@nxsoftware.com'

Please help, thank you :)

Code: Select all

XIncludeFile "COMatePLUS.pbi"

;{- Enumerations / DataSections
;{ Windows
Enumeration
  #Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
  #Text_Message
  #String
  #Text_2
  #Text_3
  #Editor
  #Button_Desactive
  #Button_Reactive
EndEnumeration
;}
;{ Fonts
Enumeration
  #Font_Text_Message
  #Font_String_1
EndEnumeration
;}
;}

Structure Parametres
  SpRecoContext.i
  SpeechRecoGrammar.i
EndStructure

Procedure SpeechRecoContextEvents(event.COMateObject, event$, parameterCount)
  Protected iParam.iUnknown
  Protected SpeechRecoResult.COMateObject
  Protected SpeechPhraseInfo.COMateObject
  Protected SpeechPhraseElements.COMateObject
  Protected SpeechPhraseElement.COMateObject
  Protected SpeechPhraseRule.COMateObject
  Protected Texte.s, Word.s
  Protected count.l, niveau.l, a.l
 
  ; Debug("EVT " + Str(parameterCount) + " " + event$)
 
  Select event$
    Case "FalseRecognition"
      SetGadgetText(#String, "<Unrecognized word or phrase>")
     
    Case "Recognition"
      Debug "-------------Recognition-----------------"
      iParam = event\GetObjectEventParam(4)
      If iParam
        SpeechRecoResult = COMate_WrapCOMObject(iParam)
       
        If SpeechRecoResult
          SpeechPhraseInfo = SpeechRecoResult\GetObjectProperty("PhraseInfo()")
          COMate_GetLastErrorDescription()
          If SpeechPhraseInfo
           
            Texte = SpeechPhraseInfo\GetStringProperty("GetText(0, -1, 1)")
            SetGadgetText(#String, Texte)
           
            SpeechPhraseElements = SpeechPhraseInfo\GetObjectProperty("Elements")
            If SpeechPhraseElements <> 0
              count = SpeechPhraseElements\GetIntegerProperty("Count")
              For a = 0 To count - 1
                SpeechPhraseElement = SpeechPhraseElements\GetObjectProperty("Item(" + Str(a) + ")")
                If SpeechPhraseElement <> 0
                  niveau = SpeechPhraseElement\GetIntegerProperty("ActualConfidence")
                  ; #SECLowConfidence = -1    ; niveau de reconnaissance basse
                  ; #SECNormalConfidence = 0  ; niveau de reconnaissance normal
                  ; #SECHighConfidence = 1    ; niveau de reconnaissance haute
                  ; Pour chaque mot, j'affiche le niveau de reconnaissance
                  Word = SpeechPhraseElement\getstringproperty("DisplayText")
                  Debug "Word = "+Word+" ; Niveau = " + Str(niveau)
                  SpeechPhraseElement\Release()
                EndIf
              Next a
             
              SpeechPhraseElements\Release()
            EndIf
           
            SpeechPhraseRule = SpeechPhraseInfo\GetObjectProperty("Rule")
            If SpeechPhraseRule <> 0
              rule.s = SpeechPhraseRule\GetStringProperty("Name")
              Debug "Rule = " + rule
              SpeechPhraseRule\Release()
            EndIf
           
           
            Select Rule
              Case "show"
                MessageRequester("Info", "Command = " + Rule)
              Case "hide"
                MessageRequester("Info", "Command = " + Rule)
            EndSelect
           
            SpeechPhraseInfo\Release()
          EndIf
          SpeechRecoResult\Release()
        EndIf
        iParam\Release()
      EndIf
     
    Case "Hypothesis"
      Debug "------------Hypothesis------------------"
     
      SetGadgetText(#Text_Message, "Analysis ongoing...")
     
      iParam = event\GetObjectEventParam(3)
      If iParam
        SpeechRecoResult = COMate_WrapCOMObject(iParam)
        If SpeechRecoResult
          SpeechPhraseInfo = SpeechRecoResult\GetObjectProperty("PhraseInfo()")
          If SpeechPhraseInfo
           
            Texte = SpeechPhraseInfo\GetStringProperty("GetText(0, -1, 1)")
           
            SetGadgetText(#Editor, Texte + Chr(13) + GetGadgetText(#Editor))
           
            SpeechPhraseInfo\Release()
          EndIf
          SpeechRecoResult\Release()
        EndIf
        iParam\Release()
      EndIf
     
    Case "SoundStart"
      Debug "SoundStart"
      SetGadgetText(#String, "")
     
    Case "SoundEnd"
      Debug "SoundEnd"
      SetGadgetText(#Text_Message, "Speak")
     
    Case "StartStream"
      ; Debug "StartStream"
     
    Case "EndStream"
      ; Debug "EndStream"
     
  EndSelect
EndProcedure

Procedure Load_Speech_Recognition(*Speech_Recognition.Parametres, File.s)
  Protected SpRecoContext.COMateObject
  Protected SpRecoGrammar.COMateObject
  Protected Init_Recognition.l = 0
 
  Protected SpRecognizer.COMateObject
  Protected SpeechRecognizer.COMateObject
  Protected SpObjectTokenCategory.COMateObject
  Protected SpObjectToken.COMateObject
 
 
  SpRecoContext = COMate_CreateObject("SAPI.SpInProcRecoContext")
  Debug COMate_GetLastErrorDescription()
  If SpRecoContext = 0 : Goto Clean : EndIf
 
 
  SpRecoGrammar = SpRecoContext\GetObjectProperty("CreateGrammar(0)")
  If SpRecoGrammar = 0 : Goto Clean : EndIf
 
  RecoGrammar.idispatch = SpRecoGrammar\GetCOMObject()
  If RecoGrammar = 0 : Goto Clean : EndIf
 
  RecoGrammar\QueryInterface(?IID_ISpeechRecoGrammar, @SpeechRecoGrammar_)
  If SpeechRecoGrammar_ = 0 : Goto Clean : EndIf
  SpRecoGrammar\Release()
 
  SpeechRecoGrammar.COMateObject = COMate_WrapCOMObject(SpeechRecoGrammar_)
  If SpeechRecoGrammar = 0 : Goto Clean : EndIf
 
  #SLOStatic = 0
  #SLODynamic = 1
  If SpeechRecoGrammar\invoke("CmdLoadFromFile('" + File + "', " + Str(#SLODynamic) + ")") <> 0
    Goto Clean
  EndIf
 
  If SpRecoContext\SetEventHandler(#COMate_CatchAllEvents, @SpeechRecoContextEvents()) <> 0
    Goto Clean
  EndIf
 
  SpRecognizer = SpRecoContext\GetObjectProperty("Recognizer()")
  If SpRecognizer = 0 : Goto Clean : EndIf
 
  Recognizer.idispatch = SpRecognizer\GetCOMObject()
  If Recognizer = 0 : Goto Clean : EndIf
 
  Recognizer\QueryInterface(?IID_ISpeechRecognizer, @SpeechRecognizer_)
  If SpeechRecognizer_ = 0 : Goto Clean : EndIf
 
  SpeechRecognizer.COMateObject = COMate_WrapCOMObject(SpeechRecognizer_)
  If SpeechRecognizer = 0 : Goto Clean : EndIf
 
  SpObjectTokenCategory = COMate_CreateObject("SAPI.SpObjectTokenCategory")
  If SpObjectTokenCategory = 0 : Goto Clean : EndIf
 
  #SpeechCategoryAudioIn = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\AudioInput"
  If SpObjectTokenCategory\invoke("SetId('" + #SpeechCategoryAudioIn + "', 0)") <> 0
    Goto Clean
  EndIf
 
  SpObjectToken = COMate_CreateObject("SAPI.SpObjectToken")
  If SpObjectToken = 0 : Goto Clean : EndIf
 
  Audio$ = SpObjectTokenCategory\GetStringProperty("Default()")
  Debug audio$
  If SpObjectToken\invoke("SetId('" + Audio$ + "')") <> 0
    Goto Clean
  EndIf
 
  If SpeechRecognizer\Setpropertyref("AudioInput(" + Str(SpObjectToken) + " as COMateObject)") <> 0
    Goto Clean
  EndIf
 
  ; La Règle de grammaire est active.
  #SGDSActive = 1
  If SpeechRecoGrammar\invoke("CmdSetRuleIdState(0, " + Str(#SGDSActive) + ")") <> 0
    Goto Clean
  Else
    Init_Recognition = 1
  EndIf
 
  Clean:
  If Init_Recognition = 0
    If SpRecoContext <> 0 : SpRecoContext\Release() : EndIf
    If SpRecoGrammar <> 0 : SpRecoGrammar\Release() : EndIf
    If SpeechRecoGrammar <> 0 : SpeechRecoGrammar\Release() : EndIf
  Else
    *Speech_Recognition\SpRecoContext = SpRecoContext
    *Speech_Recognition\SpeechRecoGrammar = SpeechRecoGrammar
  EndIf
 
  ProcedureReturn Init_Recognition
EndProcedure

Procedure Finish_Speech_Recognition(*Speech_Recognition.Parametres)
  Protected SpRecoContext.COMateObject
  Protected SpeechRecoGrammar.COMateObject
 
  SpRecoContext = *Speech_Recognition\SpRecoContext
  SpeechRecoGrammar = *Speech_Recognition\SpeechRecoGrammar
 
  If SpeechRecoGrammar <> 0
    ; La Règle de grammaire est inactive.
    #SGDSInActive = 0
    SpeechRecoGrammar\invoke("CmdSetRuleIdState(0, " + Str(#SGDSInActive) + ")")
    SpeechRecoGrammar\Release()
  EndIf
 
  If SpRecoContext <> 0
    SpRecoContext\SetEventHandler(#COMate_CatchAllEvents, 0)
    SpRecoContext\Release()
  EndIf
 
EndProcedure

Procedure Desactive_Recognition(*Speech_Recognition.Parametres, Valeur.l)
  Protected SpeechRecoGrammar.COMateObject
  SpeechRecoGrammar = *Speech_Recognition\SpeechRecoGrammar
 
  #SGDSInActive = 0
  #SGDSActive = 1
  If Valeur = 0
    SpeechRecoGrammar\invoke("CmdSetRuleIdState(0, " + Str(#SGDSActive) + ")")
    Debug COMate_GetLastErrorDescription()
  ElseIf Valeur = 1
    SpeechRecoGrammar\invoke("CmdSetRuleIdState(0, " + Str(#SGDSInActive) + ")")
    Debug COMate_GetLastErrorDescription()
  EndIf
 
EndProcedure

Procedure OpenWindow_Window_0()
  If OpenWindow(#Window_0, 732, 260, 600, 400, "Speech Recognition Control and Command", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar | #PB_Window_SizeGadget)
    TextGadget(#Text_Message, 0, 0, 600, 50, "Speak and say : hide or show", #PB_Text_Center)
    StringGadget(#String, 0, 95, 600, 35, "", #PB_String_ReadOnly)
    TextGadget(#Text_2, 0, 75, 600, 20, "  Recognized sentence:")
    TextGadget(#Text_3, 0, 160, 600, 20, "  Hypothetical sentence:")
    EditorGadget(#Editor, 0, 180, 600, 165, #PB_Editor_ReadOnly)
    ButtonGadget(#Button_Desactive, 60, 355, 200, 35, "Deactivate")
    ButtonGadget(#Button_Reactive, 335, 355, 200, 35, "Activate")
    DisableGadget(#Button_Reactive, 1)
    ; Gadget Fonts
    SetGadgetFont(#Text_Message, LoadFont(#Font_Text_Message, "Microsoft Sans Serif", 12, 272))
    SetGadgetFont(#String, LoadFont(#Font_String_1, "Microsoft Sans Serif", 12, 16))
  EndIf
EndProcedure

CoInitialize_(0)

File.s = "sol.xml"           ;put xml file path of "sol.xml"
If Load_Speech_Recognition(@Speech_Recognition.Parametres, File) = 0
  MessageRequester("Erreur", "Initialization of motor speech recognition failed!")
  End
EndIf

OpenWindow_Window_0()

;{- Event loop
Repeat
  Select WaitWindowEvent()
      ;/ //////////////////
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button_Desactive
          DisableGadget(#Button_Reactive, 0)
          DisableGadget(#Button_Desactive, 1)
          Desactive_Recognition(@Speech_Recognition.Parametres, 1)
         
        Case #Button_Reactive
          DisableGadget(#Button_Reactive, 1)
          DisableGadget(#Button_Desactive, 0)
          Desactive_Recognition(@Speech_Recognition.Parametres, 0)
         
      EndSelect
      ;/ ///////////////////////
    Case #PB_Event_CloseWindow
      Select EventWindow()
        Case #Window_0
          CloseWindow(#Window_0)
          Finish_Speech_Recognition(@Speech_Recognition.Parametres)
          CoUninitialize_()
          Break
      EndSelect
  EndSelect
ForEver

;}


Macro GUID(iid, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, b0)
  DataSection
    IID:
    Data.l $a0
    Data.w $a1, $a2
    Data.b $a3, $a4, $a5, $a6, $a7, $a8, $a9, $b0
  EndDataSection
EndMacro

GUID(IID_ISpeechRecoGrammar, B6D6F79F, 2158, 4E50, B5, BC, 9A, 9C, CD, 85, 2A, 09)
GUID(IID_ISpeechRecognizer, 2D5F1C0C, BD75, 4B08, 94, 78, 3B, 11, FE, A2, 58, 6C)
GUID(IID_ISpeechXMLRecoResult, AAEC54AF, 8F85, 4924, 94, 4D, B7, 9D, 39, D7, 2E, 19)

are you chinese? :D
poor English...

PureBasic & Delphi & VBA
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: COMatePLUS version 1.2

Post by Kwai chang caine »

The crazy false positive have again striking :?
I have try to use COMATE with PB v5.30 and my stupid "SYMANTEC endpoint protection" antivirus have locked it "Suspicious.cloud"
I have try with the second debogger and for sure, it's the same thing :|
Impossible to run a simple code for remote EXCEL :evil:

I have try with PB 5.22 and that's works fine 8)
I have commented the COMATE.PBI and that's works fine too in the 5.30

Decidedly, this problem of false positive begin to be blown :cry:
I say that for prevent FRED of this problem, perhaps he have a solution ...
ImageThe happiness is a road...
Not a destination
SeregaZ
Enthusiast
Enthusiast
Posts: 617
Joined: Fri Feb 20, 2009 9:24 am
Location: Almaty (Kazakhstan. not Borat, but Triple G)
Contact:

Re: COMatePLUS version 1.2

Post by SeregaZ »

how to fill correct this _COMatePLUSStatement?

i try to close exel file without save, some kind of force closing. as i found it is ActiveWorkbook.Close savechanges:=False

how to set this command correctly?

Code: Select all

  Workbook=ExcelFile\GetObjectProperty("ActiveWorkbook")
  If Workbook
    Workbook\Invoke("Close")
    Workbook\Release() ;Workbook freigeben
  EndIf
Invoke - as i see in comate - Invoke.i(command$, *hStatement=0) ;Returns a HRESULT value. #S_OK for no errors.

this *hStatement is _COMatePLUSStatement

so command must be like this:
Workbook\Invoke("Close", *hStatement) and code "eat" this. but now how to fill it correct?


i am stuck a few days with it :((( last one left and stuck. say something!!!!
Last edited by SeregaZ on Thu Mar 19, 2015 3:12 pm, edited 1 time in total.
acreis
Enthusiast
Enthusiast
Posts: 182
Joined: Fri Jun 01, 2012 12:20 am

Re: COMatePLUS version 1.2

Post by acreis »

You could try this solution from microsoft:

Code: Select all

Example 1: Close the workbook without saving changes

To force a workbook to close without saving any changes, type the following code in a Visual Basic module of that workbook:
Sub Auto_Close()
    ThisWorkbook.Saved = True
End Sub
SeregaZ
Enthusiast
Enthusiast
Posts: 617
Joined: Fri Feb 20, 2009 9:24 am
Location: Almaty (Kazakhstan. not Borat, but Triple G)
Contact:

Re: COMatePLUS version 1.2

Post by SeregaZ »

i dont understand how to apply this solution to PB code.
acreis
Enthusiast
Enthusiast
Posts: 182
Joined: Fri Jun 01, 2012 12:20 am

Re: COMatePLUS version 1.2

Post by acreis »

Try this:

Code: Select all


;/////////////////////////////////////////////////////////////////////////////////
;***COMate***  COM automation through iDispatch.
;*===========
;*
;*Excel demo.
;/////////////////////////////////////////////////////////////////////////////////

IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"
DisableExplicit


date$ = FormatDate("%dd/%mm/%yyyy", Date())

Define.COMateObject ExcelObject, WorkBook
ExcelObject = COMate_CreateObject("Excel.Application")

If ExcelObject
  If ExcelObject\SetProperty("Visible = #True") = #S_OK
    WorkBook = ExcelObject\GetObjectProperty("Workbooks\Add")
    If WorkBook
      ExcelObject\SetProperty("Cells(1,1) = 'Hello'")
      ExcelObject\SetProperty("Cells(1,2) = 'from'")
      ExcelObject\SetProperty("Cells(1,3) = 'COMate!'")
      ExcelObject\SetProperty("Cells(1,5) = 'Today$0027s date is'")  ;$0027 is a hex escape code used to insert a ' (ascii 39) character.
      ExcelObject\SetProperty("Cells(1,6) = '" + date$ + "' AS DATE")
      ExcelObject\SetProperty("Cells(4,1) = 6.25")

      ;Retrieve a double value and a date.
        dbl.d = ExcelObject\GetRealProperty("Cells(4,1)")
          MessageRequester("COMate - Excel demo", "Result Cells(4,1) : " + StrD(dbl))
      ;For the date we retrieve it in string format.
        newDate$ = ExcelObject\GetStringProperty("Cells(1,6)")
        MessageRequester("COMate - Excel demo", "Result Cells(1,6) : " + newDate$)
      WorkBook\SetProperty("Saved = #True")
      ExcelObject\Invoke("Quit()") 
      WorkBook\Release()
    EndIf
  EndIf
  ExcelObject\Release()
Else
  MessageRequester("COMate -Excel demo", "Couldn't create the application object!")
EndIf


Post Reply