Jump to content
Sign in to follow this  
JRowe

Simple Com object question

Recommended Posts

JRowe

I'm pretty sure it's simple. I'm trying to get an activex control working. The ocx is registered, the object creation is passing with flying colors.

I want to convert this to AutoIt.

Dim obj
 
 Sub Object1_Click()
   Dim ask As String
   Dim answer As String
   Dim i As Integer
 
   If IsEmpty(obj) Then Set obj = CreateObject("AIML.AIMLCtrl.1")
 
   obj.SetAIMLFile "c:\AIMLpad\myaimlset.aiml"
   obj.SetOptionsFile "c:\AIMLpad\options.ini"
 
   ask = InputBox("Ask")
   While ask <> ""
     answer = obj.Talk(ask)
     ask = InputBox(answer)
   Wend
 
 End Sub

This is what I have:

Global $g_eventerror = 0; to be checked to know if com error occurs. Must be reset after handling.
 
 $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
 
 $brain = ObjCreate("AIML.AIMLCtrl.1")
 MsgBox(0,"","loaded control")
 $brain.SetAIMLFile("c:\AIMLocx\myaimlset.aiml")
 MsgBox(0,"","loaded aiml")
 $brain.SetOptionsFile("c:\AIMLocx\options.ini")
 $ask = "Ask"
 
 MsgBox(0,"Test" , $brain.Talk($ask))
 
 
 Func MyErrFunc() 
    $HexNumber=hex($oMyError.number,8) 
    Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                 "Number is: " & $HexNumber & @CRLF & _
                 "Windescription is: " & $oMyError.windescription ) 
  
    $g_eventerror = 1; something to check for when this function returns 
 Endfunc

I have a vague idea that I should be using objEvent , but I've been trying various combinations and don't quite get it yet.

There are only 3 functions I'm trying to use: Talk(STRING) , SetAIMLFile(STRING) , and SetOptionsFile(STRING).

Talk() is the only one that returns anything. You send text, it returns a response. How do I use objEvent to access the Talk method, assuming that's what I should be doing? I am currently getting the "catastrophic failure" error.

Thanks!

Edited by JRowe

Share this post


Link to post
Share on other sites
JRowe

Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling.

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler

$brain = ObjCreate("AIML.AIMLCtrl.1")
MsgBox(0,"","loaded control")
ObjEvent($brain, "AIML_")

MsgBox(0,"","loaded control")
$brain.SetAIMLFile("c:\AIMLocx\myaimlset.aiml")
MsgBox(0,"","loaded aiml")
$brain.SetOptionsFile("c:\AIMLocx\options.ini")


AIML_Talk("Test")

Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 
 
   $g_eventerror = 1; something to check for when this function returns 
Endfunc

Func AIML_Talk($Ask)
    MsgBox(0,"blah", $brain.Talk($Ask))
EndFunc

I have a feeling I'm getting closer, but I can't find any clear examples, and the COM reference isn't quite dumb enough for me. The only example I can find that is similar to what I want to do is progandy's mammoth SAPI script: http://www.autoitscript.com/forum/index.php?showtopic=70079

[
  uuid(66AB77FE-DB2E-4F24-A659-FD0C272BA81E),
  helpstring("Dispatch interface for AIML Control")
]
dispinterface _DAIML {
    properties:
        [id(0xfffffdf3)     
]
        long ReadyState;
    methods:
        [id(0x00000001)]
        BSTR Talk(BSTR Ask);
        [id(0x00000002)]
        BSTR Reply(BSTR Tmplt);
        [id(0x00000003)]
        void SetReadyState(BSTR sState);
        [id(0x00000004)]
        void SetAimlFile(BSTR sName);
        [id(0x00000005)]
        void SetOptionsFile(BSTR sName);
        [id(0x00000006)]
        BSTR GetSecond();
        [id(0x00000007)]
        void SetSecond(BSTR sName);
        [id(0xfffffdd8)]
        void AboutBox();
};

Thought maybe that might help.

Share this post


Link to post
Share on other sites
JRowe

http://216.128.99.72/AIMLpad/ is the program I'm trying to work with.

http://216.128.99.72/AIMLpad/AIMLocx.zip

http://216.128.99.72/AIMLpad/AIMLocx_Source.zip

That's the ActiveX control and source. This is about as good as chatbots get. It's got everything from OpenCyc to ConceptNet, with a built in expert system and scripting language. :D

Share this post


Link to post
Share on other sites
PsaltyDS

I don't understand the side road you took with events, etc.

Did the original VBS you posted work? That just translates to something like this:

Global $obj

Object1_Click()

Func Object1_Click()
    Local $ask
    Local $answer

   If Not IsObj($obj) Then $obj = ObjCreate("AIML.AIMLCtrl.1")

   $obj.SetAIMLFile("c:\AIMLpad\myaimlset.aiml")
   $obj.SetOptionsFile("c:\AIMLpad\options.ini")

   $ask = InputBox("Ask", "Enter 'Ask' text: ")
   While $ask <> ""
     $answer = $obj.Talk($ask)
     $ask = InputBox("Answer = " & $answer, "Enter 'Ask' text: ")
   Wend
EndFunc

I can't test because I don't have the object loaded, because I don't download stuff from raw IP addresses, and because I have no interest in chat bots. You'll have to go to the documentation for the object you got.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
JRowe

http://www.google.com/search?hl=en&q=a...mp;aq=f&oq=

Dunno why, but that guys homepage has been that way for almost a decade. Never got around to buying a domain name, I guess. it's the AIMLPad page, first link returned by google.

Still getting catastrophic failure (8000FFFF) on any method call. I took the turn into objEvent() sort of randomly, because the SAPI example I found seemed closest in structure to what I was trying to do.

Anyway, here's the re-write with com error handler:

Global $obj
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler

Object1_Click()

Func Object1_Click()
    Local $ask
    Local $answer

   If Not IsObj($obj) Then $obj = ObjCreate("AIML.AIMLCtrl.1")

   $obj.SetAIMLFile("c:\AIMLpad\myaimlset.aiml")
   $obj.SetOptionsFile("c:\AIMLpad\options.ini")

   $ask = InputBox("Ask", "Enter 'Ask' text: ")
   While $ask <> ""
     $answer = $obj.Talk($ask)
     $ask = InputBox("Answer = " & $answer, "Enter 'Ask' text: ")
   Wend
EndFunc

Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 
 
   $g_eventerror = 1; something to check for when this function returns 
Endfunc

I used regview to verify that AIML.ocx is indeed registered and present where expected. OLEview shows the methods and properties clearly, and according to everything I've read in the Com reference, the simple rewrite should work. I tried reregistering and end up in the same boat.

Could this be an OS issue?

The docs include the sample code, some AIML specific stuff unrelated to installing or using the activex control, and this:

The class of the control is "AIML.AIMLCtrl.1".

The control has one method the returns a string called Talk(string ask),

for example: "reply = objAIML.Talk(ask)".

Share this post


Link to post
Share on other sites
Authenticity

JRowe,

Did the original VBS you posted work?

Share this post


Link to post
Share on other sites
JRowe

Yes, according to the author, it works. I dont have VB installed to check (which might well be a good idea.) I'll do that and see if it works.

Share this post


Link to post
Share on other sites
Authenticity

Nope, it doesn't work :D I've tested it on JScript, VBScript, AutoIt and always got Catastrophic Error 0x8000FFFF.

Lemme check it with Visual Basic.

Share this post


Link to post
Share on other sites
JRowe
ptrex

@JRowe

First of all the code you showed is not VBS but VB, so there is no 1 to 1 translations to AU3.

This is how it should look when translated to AU3

; Initialize COM error handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

Object1_Click()

Func Object1_Click()
   Local $obj   
   Local $ask
   Local $answer
   Local $i

   $obj = ObjCreate("AIML.AIMLCtrl.1")

   $obj.SetAIMLFile ("c:\AIMLpad\myaimlset.aiml")
   $obj.SetOptionsFile ("c:\AIMLpad\options.ini")

   $ask = InputBox("Input", "Ask")
   While $ask <> ""
     $answer = $obj.Talk($ask)
     $ask = InputBox("Input", $answer)
   Wend

EndFunc

Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"COM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
  SetError(1)  ; to check for after this function returns
Endfunc

If there is an error coming up then there might be something wrong on your machine where the COM object is not registered correctly.

Regards,

ptrex

Edited by ptrex

Share this post


Link to post
Share on other sites
JRowe

Thank you :D

Upon further reading, I noted that the example script is meant as an excel macro.

How do i go about correctly registering a control? Is there a tool or method i can use to track errors or guide me to a correct configuration?

*****

Also, it doesnt work at all as a macro. Looks like its a case of it working on the authors system but nowhere else- I've tried it on 4 different machines, various versions of XP. None4me , qq.

I will have to grab the source and make things work.

Edited by JRowe

Share this post


Link to post
Share on other sites
JRowe

Ok, recompiled, and I'm getting the same errors. How can I figure out what's broken, or debug what's going on when the catastrophic failures occur?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.