Results 1 to 6 of 6

Thread: DLL problem

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2001
    Location
    Cincinnati, OH
    Posts
    55

    DLL problem

    We're having touble with a DLL we've created in VB. When I built it I set it up to accept the database connection from the VB project that was calling it. This was working, but the DLL was unstable. My boss then went in and changed the way we declare the DLL to an Object rather than an instance of the Class. Now when we try to open an ADO recordset in the DLL using the connection it fails. My boss then decided to try opening a seperate connection in the DLL to the database, this worked for the ADO recordset, but now our combos that are linked to recordsets don't fill properly.

    I know it's pretty vague, but that is a summary and anyone that could help with ideas I can always elborate if you need it and show you some code if that would help too.

    You can pass database connections to DLLs right? And can someone give me the proper way to declare and call a DLL...it might all be stemming from that.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You should reference the dll and then just declare it as the class that it is.

    VB Code:
    1. 'after making the reference
    2. Private MyInstance as Class1
    3. Set MyInstance=New Class1
    4.  
    5. 'and when you are done with it
    6. Set MyInstance=Nothing

    And yes you should be able to pass in a connection object, I think WokaWidget built an activeX exe that does something like yours.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2001
    Location
    Cincinnati, OH
    Posts
    55
    thanks. That's what I thought. That's the way I was declaring it, and my boss changed it.

    Thanks again.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Declaring it initially as an object would use LateBinding and have a performance hit.

    VB Code:
    1. 'latebinding
    2. Private MyInstance as Object
    3. Set MyInstance=New Class1
    4.  
    5. 'or without a reference
    6. Private MyInstance as Object
    7. Set MyInstance=CreateObject("MyLib.Class1")

  5. #5
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    DLL side of project:

    In your DLL class module, you can have a sub or function procedure which accepts a recordset parameter like this:

    VB Code:
    1. [size="1"]' Needs a reference to the "Microsoft ActiveX Data Objects x.0"
    2. ' object library from the project > references menu.
    3. Private Sub WhaterYourDoingWithTheRecordset(rs As ADODB.Recordset)
    4.     MsgBox rs!Field1
    5. End Sub[/size]

    Rename the class module (i.e. clsRSSubTest) and then goto the project menu > project properties menu & change the project name (i.e. proRSTesting) before compiling this into a dll file.
    Last edited by alex_read; Oct 25th, 2002 at 04:14 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  6. #6
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    EXE side of project:

    Goto your project > references menu & add in a reference to the proRSTesting entry by checking the box beside it. Then enter this:

    VB Code:
    1. [size="1"]' Needs a reference to the "Microsoft ActiveX Data Objects x.0"
    2. ' object library from the project > references menu.
    3. Private Sub Form_Load()
    4.     Dim objDllClassRef As proRSTesting.clsRSSubTest
    5.     Dim conn As ADODB.Connection
    6.     Dim rs As ADODB.Recordset
    7.    
    8.     ' Code to setup the ado connection & populate the recordset
    9.    
    10.     'setup the dll reference and call on the sub procedure
    11.     ' passing in the recordset created above.
    12.     Set objDllClassRef = New proRSTesting.clsRSSubTest
    13.     objDllClassRef.WhaterYourDoingWithTheRecordset rs
    14. End Sub[/size]

    Edneeis is totally right, unless you use the dim & set combination as above, your program will be taking a performance & memory loss.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width