Solved

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

Posted on 2001-08-06
17
634 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
Comment Utility
Can you post a bit more of your code?
0
 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
Some code would be very useful!

regards,
CJ
0
 
LVL 1

Author Comment

by:moosach
Comment Utility
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 1

Author Comment

by:moosach
Comment Utility
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
Comment Utility
Why don't you use:

Dim u as KemLLC.User

set u=new KemLLC.User
0
 
LVL 11

Expert Comment

by:Otana
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
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
Comment Utility
Try putting the

     Dim u

inside the for loop before you create the object
0
 

Expert Comment

by:withAtwist
Comment Utility
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 27

Expert Comment

by:Ark
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now