Solved

VB DLL : After set=nothing and create object again it chrashes

Posted on 2001-08-06
17
638 Views
Last Modified: 2012-06-22
Hi,

since days I'm desperatley seeking for the solution of a very strange problem :

I wrote a simple dll which uses dll's of a 3rd party vendor to connect remotely to an application of this vendor and retrieve some data.

This works great for the first time I'm using it, either from an ASP-page or from wscript. I even can run it endlessly without any problems in this process as long as I don't free the the component with "set <obj>=nothing" and recreate it with "CreateObject". As soon as I use "set ...=Nothing" and afterwards "CreateObjects" it throws an error retrieving data. But strangely enough I can connect to this application and send data to it. Only the retrieval of data is throwing an exception.


Does anybody have an idea or can give me a hint what I can do to solve this crazy problem. I'm really stuck at the moment ...

Kind regards

Toni
0
Comment
Question by:moosach
  • 6
  • 3
  • 2
  • +6
17 Comments
 
LVL 11

Expert Comment

by:Otana
ID: 6355725
Can you post a bit more of your code?
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6355761
Some code would be very useful!

regards,
CJ
0
 
LVL 1

Author Comment

by:moosach
ID: 6355765
Hi,

well here is the wscript code I used for debugging :
Remember it runs once and then crashes. If I move the wscript.createobject and the "set u=nothing" outside the for-loop, it runs through 3 times here without any problems. If the wscript process ends and is restartet. It works again ...

CU

Toni

PS: I checked my DLL over and over again and I'm quite sure that the allocated memory is freed again and that the dll enters correctly the class_terminate event. Saw this in debug. Next createobject in wscript, the class_initialize is entered and everything in the dll  works until the first method (of 3rd party dll) retrieving data is called ...

.....................................................


dim u

for i = 0 to 3

set u = wscript.createobject("KemLLC.User")
if u.error <> "" then
     wscript.echo "createobj = " & u.error
end if

u.serverdns = "de4a052cw2k"
u.port = 2099
u.database = "livelink"
u.admid = "Admin"
u.admpwd = "schiffer"


wscript.echo "server = " & u.serverdns


u.connect
if u.error <> "" then
     wscript.echo "connerr = " & u.error
end if
wscript.echo "id = " & u.sessionid
wscript.echo "port = " & u.port

u.group = "DefaultGroup"
u.checkgroup
if u.error <> "" then
     wscript.echo "grouperror = " & u.error
else
     wscript.echo "group " & u.group & " exists"
end if

u.username = "Normalo"


u.checkuser
if u.error <> "" then
     wscript.echo "checkusererr = " & u.error
else
     wscript.echo "user " & u.username & " has id " & u.UID

end if

u.reset
if u.error <> "" then
     wscript.echo "reset = " & u.error
end if

u.firstname ="Anton"
u.lastname = "Kejr"
u.middlename =""
u.title =""
u.contact ="Somewhere 1504"
u.mailaddress ="anton.kejr@ffm2.siemens.de"
u.group = "DefaultGroup"
u.username = "WIM"
u.password = "arschloch"
u.privileges=0


u.checkgroup
if u.error <> "" then
     wscript.echo "grouperror = " & u.error
else
     wscript.echo "group " & u.group & " exists"
end if

u.checkuser
if u.error = "" then
     wscript.echo "user " & u.username & " with id " & u.UID & " already in LL => delete him "
     u.deleteuser
     if u.error <> "" then
          wscript.echo "deleteusererr = " & u.error
     end if
end if


u.adduser
if u.error <> "" then
     wscript.echo "addusererror = " & u.error
else
     wscript.echo "user " & u.username & " has id " & u.UID
end if

u.checkuser
if u.error <> "" then
     wscript.echo "checkusererr = " & u.error
else
     wscript.echo "user " & u.username & " has id " & u.UID

end if

u.deleteuser
     if u.error <> "" then
          wscript.echo "deleteusererr = " & u.error
     end if

u.disconnect
     if u.error <> "" then
          wscript.echo "disconnecterr = " & u.error
     end if
set u = nothing

next
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:moosach
ID: 6355770
Hi,

well here is the wscript code I used for debugging :
Remember it runs once and then crashes. If I move the wscript.createobject and the "set u=nothing" outside the for-loop, it runs through 3 times here without any problems. If the wscript process ends and is restartet. It works again ...

CU

Toni

PS: I checked my DLL over and over again and I'm quite sure that the allocated memory is freed again and that the dll enters correctly the class_terminate event. Saw this in debug. Next createobject in wscript, the class_initialize is entered and everything in the dll  works until the first method (of 3rd party dll) retrieving data is called ...

.....................................................


dim u

for i = 0 to 3

set u = wscript.createobject("KemLLC.User")
if u.error <> "" then
     wscript.echo "createobj = " & u.error
end if

u.serverdns = "de4a052cw2k"
u.port = 2099
u.database = "livelink"
u.admid = "Admin"
u.admpwd = "schiffer"


wscript.echo "server = " & u.serverdns


u.connect
if u.error <> "" then
     wscript.echo "connerr = " & u.error
end if
wscript.echo "id = " & u.sessionid
wscript.echo "port = " & u.port

u.group = "DefaultGroup"
u.checkgroup
if u.error <> "" then
     wscript.echo "grouperror = " & u.error
else
     wscript.echo "group " & u.group & " exists"
end if

u.username = "Normalo"


u.checkuser
if u.error <> "" then
     wscript.echo "checkusererr = " & u.error
else
     wscript.echo "user " & u.username & " has id " & u.UID

end if

u.reset
if u.error <> "" then
     wscript.echo "reset = " & u.error
end if

u.firstname ="Anton"
u.lastname = "Kejr"
u.middlename =""
u.title =""
u.contact ="Somewhere 1504"
u.mailaddress ="anton.kejr@ffm2.siemens.de"
u.group = "DefaultGroup"
u.username = "WIM"
u.password = "arschloch"
u.privileges=0


u.checkgroup
if u.error <> "" then
     wscript.echo "grouperror = " & u.error
else
     wscript.echo "group " & u.group & " exists"
end if

u.checkuser
if u.error = "" then
     wscript.echo "user " & u.username & " with id " & u.UID & " already in LL => delete him "
     u.deleteuser
     if u.error <> "" then
          wscript.echo "deleteusererr = " & u.error
     end if
end if


u.adduser
if u.error <> "" then
     wscript.echo "addusererror = " & u.error
else
     wscript.echo "user " & u.username & " has id " & u.UID
end if

u.checkuser
if u.error <> "" then
     wscript.echo "checkusererr = " & u.error
else
     wscript.echo "user " & u.username & " has id " & u.UID

end if

u.deleteuser
     if u.error <> "" then
          wscript.echo "deleteusererr = " & u.error
     end if

u.disconnect
     if u.error <> "" then
          wscript.echo "disconnecterr = " & u.error
     end if
set u = nothing

next
0
 
LVL 11

Expert Comment

by:Otana
ID: 6355792
Why don't you use:

Dim u as KemLLC.User

set u=new KemLLC.User
0
 
LVL 11

Expert Comment

by:Otana
ID: 6355802
sorry, forgot you're not using it in VB.

are you sure you set the third party dll's to nothing in your class_terminate?
0
 
LVL 1

Author Comment

by:moosach
ID: 6355806
Well easy enough :-) : In Scripting language VBScript (ASP, Wscript both using VBScript) I don't have early binding.
0
 
LVL 1

Author Comment

by:moosach
ID: 6355838
Well these 3rd party dlls are something special :

They aren't registered (can't be) and have to be treated like C++-Dlls. Well I'm asuming that are such DLL's. I have to use prototyping (got this from vendor) like this :

Declare Function LL_Initialize Lib "lapi_base.dll" (ByVal headerVersion As Long) As Long

Declare Function LL_Uninitialize Lib "lapi_base.dll" () As Long

Declare Function LL_ConnectAlloc Lib "lapi_base.dll" (ByRef connect As Long, ByVal server As String, ByVal port As Long) As Long

Declare Function LL_ConnectFree Lib "lapi_base.dll" (ByVal connect As Long) As Long

Declare Function LL_ConnectStatus Lib "lapi_base.dll" (ByVal connect As Long, ByRef status As Long, ByVal message As Long) As Long


Well there are lots of this beasts :-). As you can see even in this short excerpt, I have to use functions like alloc and free to handle them. So I have no change of set= nothing here.


0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6356177
Do you have code in class_terminate to execute "clean up" calls in the third party dlls?  You might consider putting such code in a method and calling it explicityly before terminating your reference to your object.  

Are any of the calls to the DLLs asynchronous?  If so, maybe you need to wait for a short time between destroying and re-creating your object.
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6356315
Try putting the

     Dim u

inside the for loop before you create the object
0
 

Expert Comment

by:withAtwist
ID: 6356808
Looks like the 3rd party component isn't using ReDim or Erase to clear an array in its code.  (I've written one that makes this same mistake.)  

Is there a method in the component like u.close or u.clear?  

This would have to be run to clear the array inside of the component BEFORE you use u.disconnect.  The component is poorly written.
0
 
LVL 28

Expert Comment

by:Ark
ID: 6357536
Seems it's a bug - in Class_Terminate event (which occure on Set...Nothing) your 3rd party dll doesn't clear port data/close port.

Cheers
0
 
LVL 1

Author Comment

by:moosach
ID: 6363727
Hi all,

it took a while till I could return to my problem. Sorry !

Well, I tried anything you advised :

- Dim u inside loop
- I created an own method for clean up (moved code rom class_terminate to this method)
- and so on ...

Nothing worked. I always get the same behaviour. Well it seems really a bug in this 3rd party dlls, which I'm using for the real work.

BUT : I found that my code is working perfectly on NT 4.0 !!! So it seems it is related to Win2000. The 3rd party dll seems to have problems with it. Does anybody knows about such problems ?
I have SP2 installed btw. This doesn't help either.

Well that drives me crazy ...

Toni
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6939304
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and keep them updated as the collaboration effort continues, to maintain your open and locked questions.  If you are a  KnowledgePro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer which does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item for help.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20163923.html
http://www.experts-exchange.com/questions/Q.20246978.html




**** PLEASE DO NOT AWARD THE POINTS TO ME. *****
 
------------>  EXPERTS:  Please leave your closing recommendations if this item remains inactive another seven (7) days.  If you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed here -> http://www.experts-exchange.com/commspt/Q.20277028.html
 

Moderators will finalize this question if in @7 days you have not responded.  They will either move this to the PAQ (Previously Asked Questions) at zero points, delete it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange
0
 
LVL 1

Author Comment

by:moosach
ID: 6939950
Well, the comments didn't help me, but I could find a work around :

1) Installed my dll as COM+ application and changed the properties of the terminating method to "free this dll if this method returns"

2) Reconfigured the calling asp-application to isolaated

Afterwards it worked.

How can I close this thread ?
0
 
LVL 1

Accepted Solution

by:
Moondancer earned 0 total points
ID: 6946674
Thanks for posting the solution you found outside this question thread.  I have refunded your 200 points to you and moved this question to our PAQ at zero point so it can help others, and closed it.

Moondancer - EE Moderator
0
 
LVL 11

Expert Comment

by:wrmichael
ID: 25676096
Did you have the steps to configure this as a COM+ Application?

I am having issues similar with .NET

I figure it is a managed code issue.


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question