• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 654
  • Last Modified:

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

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
moosach
Asked:
moosach
  • 6
  • 3
  • 2
  • +6
1 Solution
 
OtanaCommented:
Can you post a bit more of your code?
0
 
CJ_SCommented:
Some code would be very useful!

regards,
CJ
0
 
moosachAuthor Commented:
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
moosachAuthor Commented:
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
 
OtanaCommented:
Why don't you use:

Dim u as KemLLC.User

set u=new KemLLC.User
0
 
OtanaCommented:
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
 
moosachAuthor Commented:
Well easy enough :-) : In Scripting language VBScript (ASP, Wscript both using VBScript) I don't have early binding.
0
 
moosachAuthor Commented:
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
 
PaulHewsCommented:
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
 
Hornet241Commented:
Try putting the

     Dim u

inside the for loop before you create the object
0
 
withAtwistCommented:
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
 
ArkCommented:
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
 
moosachAuthor Commented:
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
 
MoondancerCommented:
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
 
moosachAuthor Commented:
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
 
MoondancerCommented:
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
 
Wayne MichaelSenior Software DeveloperCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 6
  • 3
  • 2
  • +6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now