Welcome to ModelRight Sign in | Join | Help
in

ModelRight 3 automation problem/bug?

Last post 07-10-2008, 1:24 PM by gwideman. 22 replies.
Page 1 of 2 (23 items)   1 2 Next >
Sort Posts: Previous Next
  •  07-04-2008, 4:27 AM 683

    ModelRight 3 automation problem/bug?

    I downloaded MR 3 community edition today, and am happy to see some great features, especially the prospect of using automation aka scripting.  However, there seems to be a problem using the automation API from external automation clients.

    It appears to me that the path to do that is via SCF.dll, as encouraged by this post: "HTML file that uses JavaScript to read and display model info". 

    However, that COM object doesn't appear to be registered, and attempting to run regsrv32 on SCF.dll results in "specified module not found" error.

    Obviously the DLL itself is there, however, opening the DLL in Dependency Walker shows that it's expecting to use MFC80.DLL, MSVCR80,DLL, MSVCP80.DLL and ATL80.DLL, all marked as not found on my system (XP SP2).

    Is there a workaround for this?

    Thanks, Graham

    Filed under: , ,
  •  07-04-2008, 6:23 AM 690 in reply to 683

    Re: ModelRight 3 automation problem/bug?

    Hmmm.  Yes, that used to work.  We'll investigate
    Scott Reynolds
    Senior Technical Support
    ModelRight, Inc.
  •  07-04-2008, 8:33 AM 691 in reply to 683

    Re: ModelRight 3 automation problem/bug?

    should be fixed in the next build - due out early next week (July 7)
    Scott Reynolds
    Senior Technical Support
    ModelRight, Inc.
  •  07-04-2008, 5:11 PM 693 in reply to 691

    Re: ModelRight 3 automation problem/bug?

    Thanks admin, I'll look for that,

    Graham

  •  07-07-2008, 2:54 PM 704 in reply to 693

    Re: ModelRight 3 automation problem/bug?

    Please give this a try (running regsvr32 on scf.dll) in the latest build (3044).
    Scott Reynolds
    Senior Technical Support
    ModelRight, Inc.
  •  07-08-2008, 2:45 AM 705 in reply to 704

    ModelRight 3 automation bug: 3044 SCF test report

    Hi Scott:

    Earlier I posted results of a lengthy SCF testing session here with all sorts of failures. Then I noticed a Framework.Initialize procedure, which lets me get a bit further. So this is a temporary message removing my previous report, to avoid you working on that. Meantime I'm writing up a new report.

    Graham

    Filed under: , , ,
  •  07-08-2008, 4:32 AM 706 in reply to 704

    MR 3044 automation: SCF test report WITH Initialize

    Hi Scott:

    I can get SCF.dll build 3044 to partially work, but not usefully, and there really isn't enough doc to figure out how your automation objects are supposed to work from an automation client. Not the least problem is that I'm unclear what SCF interfaces to -- does it try to talk to the running app (like how all the Office products work), or is it a totally stand-alone thing that interacts only with files, and/or builds models in memory? Certainly when I engage SCF I don't see MR appear in the Task Manager (and having MR running doesn't seem to make things work better).

    Anyhow, here's what I tried, and what failed.

    Environment: Windows XP SP2.

    1. Uninstall previous edition of MR (I think it was 3042).

    2. Install 3044 (at different path).

    3. Start a VBA project in Excel, and try to use the Tools > References procedure to enable use of SCF.dll. It appears in the list (SCF 1.0 Type Library), however OK'ing that results in "dll not available" error. Maybe registry still has path to uninstalled dll.

    4. Run regsrv32 on SCF.dll. Indicates success.

    5. In VBA try References procedure... success.  Can browse SCFLib objects in Object Browser.

    6. Proceed to adapt the sample routine from Help into VBA, as follows:

    -----------------------------------------
    Sub Test()
    Dim Framework As ScriptFramework
    Dim Models As MRModelCollection
    Dim Model As MRModel
    Dim Tables As MRObjectCollection
    Dim Table As MRObject
    Dim PropValue As MRPropertyValue

    Dim V As Variant

      Set Framework = CreateObject("SCF.ScriptFramework")
      Framework.Initialize     ' <-- Apparently needed
     
    '--------- 1. Try ActiveModels ----------
    '  Set V = Framework.ActiveModels  ' <-- returns Nothing
    '  Set Models = V
    '  Set Model = Models.Item(1)
     
    '--------- 2. Try CreateModel ----------
    '  Set Model = Framework.CreateModel '  <-- Error
             ' Unable to load library DBFMySQLFE, 126
            
    '--------- 3. Try LoadModel ----------
      Set Model = Framework.LoadModel(APath) ' APath is a legit wer file
      Debug.Print Model.Name, Model.ID       ' Succeeds
     
      Model.BeginTransaction ("Batch Rename Tables")

      Set V = Model.AsObject.Children("Table") ' Error 80010108
        ' Method Children of ISCFObject failed

      For Each Table In Tables
        Set PropValue = Framework.CreatePropertyValue("Table", "Name")
        PropValue.FromString ("T_" + Table.Name)
        Table.SetProperty "Name", PropValue
      Next

      Model.EndTransaction

    End Sub
    -----------------------------------------

    This compiles (with Option Explicit), but falls down in various ways.

    First off, it took several hours to guess that Framework.Initialize is needed. Not sure why newly constructed Fraemwork needs initializing, but without it pretty much nothing works, and some Framework methods cause hard crash in VBA/Excel.

    But, assuming Initialize is the right thing to do...

    As you can see, I tried three different Framework methods:

    -- ActiveModels: consistently returns VBA Nothing (ie: nul).  Perhaps ActiveModels only applies to the running app, and hence to scripting within the app?

    -- CreateModel:  Always fails with error shown

    -- Load Model: Succeeds, and can then proceed to read Model.Name and Model.ID.  However, Model.AsObject.Children fails. with error shown.  I tried rearranging like this:

    Dim MRO As MRObject
      Set MRO = Model.AsObject
      Set V = MRO.Children("Table")  ' <-- Hard crash VBA/Excel

    MRO gets a non-Nothing value, but MRO.Children crashes.


    7. In VBA Object Browser I see that ActiveModel returns type "Unknown". This article at MS:
    http://support.microsoft.com/kb/q194913/
    seems to say that "Unknown" in Object browser means a type incompatible with VBA/VB. By contrast, Object Browser shows that CreateModel returns "Object", but as noted above, attempting to use that method causes a crash.

    8. I tried interfacing to SCF.dll from Delphi.  Delphi was able to import SCF's type library with no problem, and creates an interface with a more detailed view of types than VBA Object Browser. I basically got the same results using equivalent Delphi code.  At this step:

    -----------------------
      Unk    := Model.AsObject;
      MRO    := Unk as MRObject;

      Unk    := MRO.Children('Table');     // <-- Exception
      Tables := Unk as MRObjectCollection;
    -----------------------
    .. I get an exception showing access violation in SCF.dll at 00BC4C50, read of address 0000018. (Ie: same spot where VBA crashed.)

    9. Dependency Walker on SCF.dll: It continues to show various dependencies not found, like MFC80.DLL and numerous friends. It would be nice to know whether SCF is capable of functioning properly if those dependencies are broken.

    ==============================

    Suggestions for progress:
    ------------------------

    Sample code: I feel like there's way too much guesswork for me to troubleshoot this effectively. What would be great is some simple VBA sample code that you guys have seen working, and a description of the test setup required.

    Anyhow, I hope that helps,

    Graham

    Filed under: , , ,
  •  07-08-2008, 6:13 AM 707 in reply to 706

    Re: MR 3044 automation: SCF test report WITH Initialize

    Ok.  I can reproduce a problem with the Children method.  We'll investigate that.

     BTW, ModelRight support VBScript and JavaScript, not VBA.  Not sure if you can run from VBScript from VBA?  Do you know?


    Scott Reynolds
    Senior Technical Support
    ModelRight, Inc.
  •  07-08-2008, 6:37 AM 708 in reply to 707

    Re: MR 3044 automation: SCF test report WITH Initialize

    > BTW, ModelRight support VBScript and JavaScript, not VBA

    The interface that SCF exposes is a COM Automation interface, ie: it is an Automation server. Therefore any client that can talk to an Automation server should be able to use it.

    That said, there are wrinkles:

    1. It's possible to write an automation server using features that VB/VBA is unable to talk to. Despite VB being heavily based around COM objects, VB doesn't support all data types that COM does, and consequently can be unable to interact with parts of the automation server's API.  (That's why I also tried SCF with Delphi, tho in this case I'm not convinced this is the variety of trouble we're running into.)

    2. If you provide an automation server that is covered in IUnknown or IDispatch or other really generic interfaces, that's usable but difficult, because it defeats all the really useful support that IDEs give you when they know what types are returned by methods. In some languages it requires a bunch of fiddling with poorly-documented areas in order to coerce the generic types into properly-typed variables so that you can access their member methods/properties.

    3. I would sure hope it is an objective to allow talking to MR via automation as that covers a bunch of really useful use cases that so far as I'm aware other vendors aren't serving!

    Anyhow, I am very interested to get an assessment of viability of SCF for external automation clients, because as I say this opens up some compelling possibilities.

    Graham

  •  07-08-2008, 8:00 AM 709 in reply to 708

    Re: MR 3044 automation: SCF test report WITH Initialize

    Hi Graham,

     Just couple of quick notes:

    1. I thinkl that our scripting model should work with VBA.

    2. As you noted, Initialize must be called before doing anything else. However, Initialize is only needed when running a script outside ModelRight enviroment (i.e. stand alone script). If run it inside the product, then Initialize is already called for you.

    3. ActiveModels returns a list of all models that are either loaded or created during a session. At the time when you call it, there is no model loaded or created.

     As I mentioned before, we're working on a document to explain the basics of MR scripting, including some of the issues you ran into.

     


    ModelRight Evangelist
  •  07-08-2008, 8:18 AM 710 in reply to 709

    Re: MR 3044 automation: SCF test report WITH Initialize

    > we're working on a document to explain the basics of MR scripting

    Yes I did catch that, and yes please!   Not sure if I can be of help, but let me know if you think so.

    Thanks,

    Graham

  •  07-08-2008, 8:50 AM 711 in reply to 710

    Re: MR 3044 automation: SCF test report WITH Initialize

    Its a very strange problem.  MR is failing to CoCreateInstance an instance of a class that creates a collection.  Its odd because obviously the dll is registering successfully and other methods are working...  Continuing the investigation...


    Scott Reynolds
    Senior Technical Support
    ModelRight, Inc.
  •  07-08-2008, 3:20 PM 712 in reply to 711

    Re: MR 3044 automation: SCF test report WITH Initialize

    Also, it seems to work on Vista, but not XP.
    Scott Reynolds
    Senior Technical Support
    ModelRight, Inc.
  •  07-08-2008, 5:39 PM 713 in reply to 712

    Re: MR 3044 automation: SCF test report WITH Initialize

    > Also, it seems to work on Vista, but not XP.

    I again direct your attention to the fact that the DLL has a bunch of dependencies on modules MFC80.DLL, MSVCR80,DLL, MSVCP80.DLL and ATL80.DLL (Visual Studio 2005?) that aren't installed by default on XP.  As can be seen in Dependency Walker.

    In particular, ATL is the Active Template Library, which includes code for Collections. So not having ATL could cause access to collections to fail... like

    Set V = MRO.Children("Table")   

    I don't know this to be the problem, but it's a possibly glaring difference between XP and Vista, and it sounds like a good theory :-).

     Graham

  •  07-08-2008, 8:15 PM 714 in reply to 712

    Re: MR 3044 automation: SCF "success"

    Hi Scott and modelright:

     I have got the sample code to run, but the process required strongly suggests problems in the preparation of SCF.dll for deployment.  First the test conditions:

    SCF.dll 3044. WinXP, SP2, Visual Studio 2005 NOT installed.  Using VBA in Excel 2003.

    The sample VBA procedure:

    ---------------------------------------

    Sub Test()
    Dim Framework As ScriptFramework
    Dim Models As MRModelCollection
    Dim Model As MRModel
    Dim Tables As MRObjectCollection
    Dim Table As MRObject
    Dim PropValue As MRPropertyValue
    Dim MRO As MRObject

    Dim V As Variant

      Set Framework = CreateObject("SCF.ScriptFramework")
      Framework.Initialize     ' <-- Apparently needed
            
    '--------- 3. Try LoadModel ----------
      Set Model = Framework.LoadModel(LoadPath) ' OK
      Debug.Print Model.Name, Model.ID       ' Succeeds
     
      Model.BeginTransaction ("Batch Rename Tables")
     
      Set MRO = Model.AsObject
      Set V = MRO.Children("Table") ' Error WAS here
       
      Set Tables = V

      For Each Table In Tables
        Debug.Print Table.Name, Table.ID
        Set PropValue = Framework.CreatePropertyValue("Table", "Name")
        PropValue.FromString ("T_" + Table.Name)
        Table.SetProperty "Name", PropValue
      Next

      Model.EndTransaction
      Framework.SaveModel SavePath, Model

    End Sub

    -----------------------------------------------

    1. I noted that the version of Dependency Walker that was getting launched was from VS6, and didn't know about newer dependencies, so I obtained latest DW 2.2.  This reinforced missing VS2005 dependencies.

    2. I obtained from MS the VS 2005 redistributables (regular and SP1), and installed them.  This resulted in fewer missing dependencies in DW. 

    3. DW still says "errors detected", and thinks that SCF.dll is looking for MFC80.DLL, MSVCP80.DLL, MSVCR80.DLL in the MR home directory (or maybe doesn't find compatible versions in winsxs).  However, there are other refs to these DLLs that DW successfully resolves to the shared assemblies in winsxs.  Not sure what to make of that, but I carried on regardless.

    4. At this stage, running the above test proc continued to crash VBA and Excel when executing the MRO.Children line.  So I stepped to that point while watching file activity in FileMon. After earlier statements correctly accessing SCF.dll in MR's home dir, at that statement Excel/VBA looks for SCF.dll in Excel's executable directory!  (..OFFICE11/bunch-of-exes).  ... which fails, leading to Dr Watson etc.

    5. So I copied SCF.dll to Excel's exe directory.  Result was similar but did proceed further, looking for MR's ot900as.dll in Excel directory.

    6. I copied ot900as.dll to the Excel dir.

    Presto, now the VBA sample code runs, iterates through the tables, modifies the names and saves the model, as judged by subsequently loading it into MR.  (FWIW, this is a model of mysql's sakila demo DB).

    The one bad thing is that trying to run it a *second time* within Excel causes a crash at the LoadModel statement, indicating that cleanup didn't happen automatically at end of previous execution, (eg: VB garbage collection on Framework fails to prompt GC cleanup) and/or Initialize is quite initial enough :-).

    Anyhow... it runs.  I don't think I trust it enough to do serious work on it at this stage, but hopefully all these clues are helpful in your tracking down the problems.

    Graham

    Filed under: , , ,
Page 1 of 2 (23 items)   1 2 Next >