|
-
Oct 24th, 2002, 09:13 AM
#1
Thread Starter
Member
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.
-
Oct 24th, 2002, 10:24 AM
#2
You should reference the dll and then just declare it as the class that it is.
VB Code:
'after making the reference
Private MyInstance as Class1
Set MyInstance=New Class1
'and when you are done with it
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.
-
Oct 24th, 2002, 10:38 AM
#3
Thread Starter
Member
thanks. That's what I thought. That's the way I was declaring it, and my boss changed it.
Thanks again.
-
Oct 24th, 2002, 11:21 AM
#4
Declaring it initially as an object would use LateBinding and have a performance hit.
VB Code:
'latebinding
Private MyInstance as Object
Set MyInstance=New Class1
'or without a reference
Private MyInstance as Object
Set MyInstance=CreateObject("MyLib.Class1")
-
Oct 25th, 2002, 04:07 AM
#5
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:
[size="1"]' Needs a reference to the "Microsoft ActiveX Data Objects x.0"
' object library from the project > references menu.
Private Sub WhaterYourDoingWithTheRecordset(rs As ADODB.Recordset)
MsgBox rs!Field1
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.
-
Oct 25th, 2002, 04:13 AM
#6
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:
[size="1"]' Needs a reference to the "Microsoft ActiveX Data Objects x.0"
' object library from the project > references menu.
Private Sub Form_Load()
Dim objDllClassRef As proRSTesting.clsRSSubTest
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
' Code to setup the ado connection & populate the recordset
'setup the dll reference and call on the sub procedure
' passing in the recordset created above.
Set objDllClassRef = New proRSTesting.clsRSSubTest
objDllClassRef.WhaterYourDoingWithTheRecordset rs
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|