ActiveX Access

Discussion in 'AutoCAD' started by Ralf Davi, Jul 8, 2003.

  1. Ralf Davi

    Ralf Davi Guest

    Hi.
    I'm trying to access a simple vb component thru ActiveX.
    It is just a simple test of connect to a VB Component, but I can't get
    it right.

    This is the Visual Basic Code...
    ---------------------------------------------------------------------------
    Public Function StrConcat(str1 As String, str2 As String) As Variant
    StrConcat = (str1) & (str2)
    End Function
    ---------------------------------------------------------------------------

    ....and this is the VLisp Code:
    ---------------------------------------------------------------------------
    (vl-load-com)

    (defun vbStrCat (string1 string2 / $acad vbstrcls out)
    (setq $acad (vlax-get-acad-object))
    (setq vbstrcls
    (vla-GetInterfaceObject $acad "vbStringClass.vbStrings"))
    (setq out (vlax-invoke-method vbstrcls "StrConcat" string1 string2))
    out
    (vlax-release-object vbstrcls)
    (vlax-release-object $acad)
    )
    ---------------------------------------------------------------------------

    So, when i load and call it from Autocad command line (vbStrCat "test1"
    "teste2"), it gives me this text: "#<variant 8 >".

    Does anybody knows where is the error and how to fix it ?

    Thanks a lot.
     
    Ralf Davi, Jul 8, 2003
    #1
  2. Ralf Davi

    Ralf Davi Guest

    I tried this and i got a blank string.

    Command: (vbStrCat "s" "r")
    ""
    I got this "". Have any idea ?
     
    Ralf Davi, Jul 8, 2003
    #2
  3. Ralf Davi

    Mark Propst Guest

    trying to duplicate what you've got
    i've never tried to use vb from lisp so what did you name your class module
    in this example
    I saved a class with your function as vbStringClass.cls in my vb dir
    do I need to have the class in a dvb or vbp?
    or can I access it directly?

    "vbStringClass.vbStrings"

    in your class I changed your function to:

    Public Function StrConcat(str1 As String, str2 As String) As String
    StrConcat = str1 & str2
    End Function

    I don't understand why pass a variant also dropped the parens around str1
    and str2
    but cant' test until I figure how to refer to in lisp
     
    Mark Propst, Jul 8, 2003
    #3
  4. Ralf Davi

    Ralf Davi Guest

    You need to compile it. Make a DLL. If you are using VB 6.0, just open
    the class and point the File menu and then click "Make
    vbStringClass.dll...". click "ok" and thats it. It automatically register
    the dll in Windows and afterwards u can use.

    My goal using this VB ActiveX is to connect to a Microsoft Access
    database (and maybe a SQL-Server after). I just know how to do this using
    VB, so I tried this.
    Do you know a simplier way ?

    I'm very newbie in Lisp programming...

    Thanks a lot.
     
    Ralf Davi, Jul 8, 2003
    #4
  5. Ralf Davi

    Mark Propst Guest

    if I open vbStringClass.cls in vb6 and go file - make dll
    I get make Project1.exe?
    if I start a new project as activex dll and import the string class I get an
    error when I try to compile
    no creatable something or other
    should this function be in a class module or a std module?
    does the project name dictate the dll name? apparently it does
    or am I doing something else wrong?

    did my change to your function help or not?
    thanks
     
    Mark Propst, Jul 8, 2003
    #5
  6. Ralf Davi

    Mark Propst Guest

    generally I thought one wanted to avoid variants if possible,
    are you saying that the other types will not pass across the dll-lisp
    boundary?
    I rewrote his function As String and got a numeric result, maybe that's why?
    also I thought this line
    is that not correct?
     
    Mark Propst, Jul 8, 2003
    #6
  7. Ralf Davi

    NateB Guest

    I tried the same sample, and it didn't work for me either. When I would check the variant value, I would also get an empty string. I've only been using the Acad/ActiveX features for a few weeks, and haven't had very much luck with it. I've tried creating a couple of different projects while learning to interface between applications. One problem I found was with the following sample:

    The VB6 code is:

    Public Function vbMessageBox(TxtStr As String, dlgType As Integer, TitleStr As String) As Variant
    &nbsp;&nbsp;&nbsp;&nbsp;vbMsgBox = MsgBox(TxtStr, dlgType, TitleStr)
    End Function

    The interfacing LISP code is:

    (defun MessageBox ( msgStr dlgType msgTitle / acadObj vbIOCls retVal )
    &nbsp;&nbsp;(setq acadObj (vlax-get-acad-object)
    vbIOCls (vla-GetInterfaceObject acadObj "vbIOInterface.vbMsg")
    retVal (vlax-Invoke-Method vbIOCls "vbMessageBox" msgStr dlgType msgTitle)
    &nbsp;&nbsp;)
    &nbsp;&nbsp;(vlax-Release-Object vbIOCls)
    &nbsp;&nbsp;(vlax-Release-Object acadObj)

    retVal
    )

    When I enter the following code:
    (MessageBox "Test MessageBox" 0 "Message Title")
    an empty message box is displayed, and an empty variant is returned. If I use the (vlax-Invoke), instead of (vlax-Invoke-Method) the text is displayed properly in the messagebox, but it returns nil. This should return 1 (the value of the vbOK constant). I've tried using several different datatypes, for the input/output values of the Function, but nothing seems to get the expected results. I'm not sure what the problem is, but I've tried it in both Acad 2002 and Acad 2004, with the same outcome. I'm hoping for better result using VB.NET. Don't know!
     
    NateB, Jul 9, 2003
    #7
  8. Ralf Davi

    Mark Propst Guest

    Yeah, it seems like there's a problem passing values from vb to the calling
    lisp
    I was able to pass a byref arg from lisp (quoted symbol) to vb and have it
    set inside the dll, and afterwards the lisp variable did have the correct
    value (a string)
    but now I'm trying to modify the file and I get "
    ; error: ActiveX Server returned the error: unknown name: Hello
    even though the sub or function is in there and I re-made the dll
    who knows:? not sure I need this enough to waste much more time on it,
    though it seems like it could be handy if you could call a vb form from
    lisp.
    then, may as well just use vb, why mix it with lisp?


    I tried the same sample, and it didn't work for me either. When I would
    check the variant value, I would also get an empty string. I've only been
    using the Acad/ActiveX features for a few weeks, and haven't had very much
    luck with it. I've tried creating a couple of different projects while
    learning to interface between applications. One problem I found was with the
    following sample:
    The VB6 code is:
    Public Function vbMessageBox(TxtStr As String, dlgType As Integer, TitleStr
    As String) As Variant
    vbMsgBox = MsgBox(TxtStr, dlgType, TitleStr)
    End Function
    The interfacing LISP code is:
    (defun MessageBox ( msgStr dlgType msgTitle / acadObj vbIOCls retVal )
    (setq acadObj (vlax-get-acad-object)
    vbIOCls (vla-GetInterfaceObject acadObj "vbIOInterface.vbMsg")
    retVal (vlax-Invoke-Method vbIOCls "vbMessageBox" msgStr dlgType msgTitle)
    )
    (vlax-Release-Object vbIOCls)
    (vlax-Release-Object acadObj)
    retVal
    )
    When I enter the following code:
    (MessageBox "Test MessageBox" 0 "Message Title")
    an empty message box is displayed, and an empty variant is returned. If I
    use the (vlax-Invoke), instead of (vlax-Invoke-Method) the text is displayed
    properly in the messagebox, but it returns nil. This should return 1 (the
    value of the vbOK constant). I've tried using several different datatypes,
    for the input/output values of the Function, but nothing seems to get the
    expected results. I'm not sure what the problem is, but I've tried it in
    both Acad 2002 and Acad 2004, with the same outcome. I'm hoping for better
    result using VB.NET. Don't know!
     
    Mark Propst, Jul 9, 2003
    #8
  9. This should work fine:

    (setq ACD(vlax-get-acad-object))
    (setq SRV (vlax-invoke ACD "getinterfaceobject" "vbStringClass.vbStrings"))
    (setq RET (vlax-invoke SRV "StrConcat" string1 string2))

    and your DLL function:

    Public Function StrConcat(str1 As Variant, str2 As Variant) As Variant
    StrConcat = str1 & str2
    End Function

    If this doesn't work for you then there must be a problem with the way you
    created your class.
     
    Jorge Jimenez, Jul 9, 2003
    #9
  10. Ralf Davi

    Ralf Davi Guest

    I've tried and it doesn't worked either, but thanks anyway.

    Have any other idea ? Please send me...

    Thank you : )


    Ralf Davi.
     
    Ralf Davi, Jul 10, 2003
    #10
  11. This should work fine:

    (setq ACD(vlax-get-acad-object))
    (setq SRV (vlax-invoke ACD "getinterfaceobject" "vbStringClass.vbStrings"))
    (setq RET (vlax-invoke SRV "StrConcat" string1 string2))

    and your DLL function:

    Public Function StrConcat(str1 As Variant, str2 As Variant) As Variant
    StrConcat = str1 & str2
    End Function

    If this doesn't work for you then there must be a problem with the way you
    created your class.
     
    Jorge Jimenez, Jul 11, 2003
    #11
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.