Page 1 of 2 12>
Topic Options
#203747 - 2011-11-16 04:52 PM Is there an opposite to CreateObject() ?
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
This is an old problem that I've managed to work around using getfileversion(), but just out of curiosity does anybody know how to release an object once it's created? I expected a simple $system = 0 to do the trick, but the file lock remains. Is it expected behavior for object creation, or is it just kixforms?

In the below example, I can never replace kixforms.dll because the file remains locked.
 Code:
$System = CreateObject("Kixtart.Form")

if CompareVerString($System.Version, "2.47.5.1") = 1
   $System = 0
   $oldkf = ReadValue("HKEY_CLASSES_ROOT\CLSID\"+ReadValue("HKEY_CLASSES_ROOT\Kixtart.System\CLSID","")+"\InprocServer32","")
   Copy @ScriptDir+"\kixforms.dll" $oldkf
? @Error
? @SError
   $System = CreateObject("Kixtart.System")
endif

get $

Function CompareVerString($_Version1, $_Version2)
  Dim $_X, $_Max
  $_Version1 = Split($_Version1, '.')
  $_Version2 = Split($_Version2, '.')
  $_Max=IIf(UBound($_Version1)>UBound($_Version2),UBound($_Version1),UBound($_Version2))
  ReDim Preserve $_Version1[$_Max]
  ReDim Preserve $_Version2[$_Max]
  For $_X = 0 to $_Max
    Select
     Case CInt($_Version1[$_X]) < CInt($_Version2[$_X])
      $CompareVerString=1  Exit 0
     Case CInt($_Version1[$_X]) > CInt($_Version2[$_X])
      $CompareVerString=-1 Exit 0
    EndSelect
  Next
  Exit 0
EndFunction

Top
#203748 - 2011-11-16 04:58 PM Re: Is there an opposite to CreateObject() ? [Re: ShaneEP]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
In this case wouldn't you have to unregister the dll, copy the file , and then reregister the dll before it would work?

Did you see my post about cdo holding files open with Sendmail UDF?

Top
#203756 - 2011-11-16 08:11 PM Re: Is there an opposite to CreateObject() ? [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Yes, it would need to be re-registered, I just wrote that snippet to demonstrate the file lock problem. But I took a look at your sendmail post. Must not be a kixforms issue.
Top
#203757 - 2011-11-16 09:29 PM Re: Is there an opposite to CreateObject() ? [Re: ShaneEP]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
Okay... will you try this?

 Code:
$System=Nothing()

function Nothing()
  dim $sc
  $sc = CreateObject("ScriptControl")
  $sc.language = "VBScript"
  $sc.addcode('noth=nothing')
  $sc.run
  $nothing=$sc.codeobject.noth  
endfunction


I am trying it now on sendmail.

Top
#203758 - 2011-11-16 09:37 PM Re: Is there an opposite to CreateObject() ? [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
I thought about that because of your windows update session post earlier, but I couldn't get it to work with kixforms. I was probably just doing something wrong.
Top
#203759 - 2011-11-16 09:46 PM Re: Is there an opposite to CreateObject() ? [Re: ShaneEP]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
Fixed the sendmail with this. Hot digity!
Top
#203763 - 2011-11-16 11:31 PM Re: Is there an opposite to CreateObject() ? [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
I dont seem to be having as much luck. Can you see something wrong with this? I tried to imitate what you did with sendmail().

 Code:
$sc=CreateObject("ScriptControl")
$sc.language = "VBScript"
$sc.addcode('noth=nothing')
$sc.run

$System = CreateObject("Kixtart.Form")

if CompareVerString($System.Version, "2.47.5.1") = 1
   $System=$sc.codeobject.noth
   $oldkf = ReadValue("HKEY_CLASSES_ROOT\CLSID\"+ReadValue("HKEY_CLASSES_ROOT\Kixtart.System\CLSID","")+"\InprocServer32","")
   Copy @ScriptDir+"\kixforms.dll" $oldkf
   ? @Error
   ? @SError
endif

get $

Function CompareVerString($_Version1, $_Version2)
  Dim $_X, $_Max
  $_Version1 = Split($_Version1, '.')
  $_Version2 = Split($_Version2, '.')
  $_Max=IIf(UBound($_Version1)>UBound($_Version2),UBound($_Version1),UBound($_Version2))
  ReDim Preserve $_Version1[$_Max]
  ReDim Preserve $_Version2[$_Max]
  For $_X = 0 to $_Max
    Select
     Case CInt($_Version1[$_X]) < CInt($_Version2[$_X])
      $CompareVerString=1  Exit 0
     Case CInt($_Version1[$_X]) > CInt($_Version2[$_X])
      $CompareVerString=-1 Exit 0
    EndSelect
  Next
  Exit 0
EndFunction

Top
#203764 - 2011-11-16 11:44 PM Re: Is there an opposite to CreateObject() ? [Re: ShaneEP]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
that nothing has nothing to do with nothing.
if you want to make a value contain null, you use not 1.

if you want the var to contain nothing, you use redim.
anyways, setting a var that contains the last object reference to anything else, like zero, WILL and MUST dispose the object and release all hooks.
there is something wrong with something if this doesn't happen.
and it shouldn't matter how many nothings and nulls you put in place of trashing the object reference, it should always behave the same.

that being said, what is the error you get it with?
also I would consider there is some windows crap going on, so there might be a need for a delay, after release of the object.
_________________________
!

download KiXnet

Top
#203765 - 2011-11-16 11:51 PM Re: Is there an opposite to CreateObject() ? [Re: Lonkero]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
I assumed the same as you're saying, but it just doesn't. If I run the below test script I get error 32 "The process cannot access the file because it is being used by another process.". Even withe the redim and a 15 second sleep.

 Code:
$System = CreateObject("Kixtart.Form")

if $System.Version <> "2.47.5.1"
   $System = 0
   ReDim $System
   Sleep 15
   $oldkf = ReadValue("HKEY_CLASSES_ROOT\CLSID\"+ReadValue("HKEY_CLASSES_ROOT\Kixtart.System\CLSID","")+"\InprocServer32","")
   Copy @ScriptDir+"\kixforms.dll" $oldkf
   ? @Error
   ? @SError
endif

get $

Top
#203766 - 2011-11-16 11:55 PM Re: Is there an opposite to CreateObject() ? [Re: ShaneEP]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
Sorry dude, it looks right. Must not be the golden pill. The function should have worked too.
Top
#203767 - 2011-11-17 12:01 AM Re: Is there an opposite to CreateObject() ? [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
going to test it now with simple trace with: http://technet.microsoft.com/en-us/sysinternals/bb896653
_________________________
!

download KiXnet

Top
#203768 - 2011-11-17 12:30 AM Re: Is there an opposite to CreateObject() ? [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok, that didn't work as it didn't show anything \:o
_________________________
!

download KiXnet

Top
#203769 - 2011-11-17 12:39 AM Re: Is there an opposite to CreateObject() ? [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
listdlls doesn't show it either.
anyways, created a script that loaded a form.
before closing it, opened up a command prompt and renamed kixforms.dll to kixforms.old.dll

no errors.
then in the script window hit a key and let it dispose with $Form = 0

so, even if the form is loaded, kixtart doesn't block it from being renamed.
your systems have something else going on!
_________________________
!

download KiXnet

Top
#203770 - 2011-11-17 12:42 AM Re: Is there an opposite to CreateObject() ? [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh, and weird thing...
the form didn't get destroyed with $Form = 0
only after that I had put a redim that destroyed it!
so there is some iffy going on after all...

 Code:
$F = CreateObject("Kixtart.Form")
@error ?
$F.show
"pausing start. see if dll shows up loaded. continue after."
get $ cls ?
   $SF = 0
"pausing release. see if dll shows up loaded. continue after."
get $ cls ??
   ReDim $F
"pausing redim. see if dll shows up loaded. quit after."
get $
_________________________
!

download KiXnet

Top
#203771 - 2011-11-17 12:58 AM Re: Is there an opposite to CreateObject() ? [Re: Lonkero]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
$SF = 0 should be $F = 0 ?
Top
#203772 - 2011-11-17 01:09 AM Re: Is there an opposite to CreateObject() ? [Re: ShaneEP]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol, yea. thanks for having better eyes today \:\)

and indeed, setting to 0 does destroy the hook, just like it should.

and, like already said, even when kixforms is in use, it is still able to be renamed.
_________________________
!

download KiXnet

Top
#203773 - 2011-11-17 02:38 AM Re: Is there an opposite to CreateObject() ? [Re: Lonkero]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
Guess I got carried away with the scriptcontrol...

 Quote:

if you want to make a value contain null, you use not 1.


I just tried that, and it returned boolean.

Cleaned up my code in the Sendmail to just use a dimmed, but unused var called $Empty, and it worked like a charm. I'm sure the redim would have worked as well.

Top
#203774 - 2011-11-17 03:12 AM Re: Is there an opposite to CreateObject() ? [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yea, boolean false...
my head just doesn't work today...
_________________________
!

download KiXnet

Top
#203783 - 2011-11-17 08:43 PM Re: Is there an opposite to CreateObject() ? [Re: Lonkero]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Weird. You're right, once I set it to 0 or redim it, I can indeed rename it and unregister/re-register...but the straight Copy still gives an error.
Top
#203784 - 2011-11-17 08:44 PM Re: Is there an opposite to CreateObject() ? [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
So I guess it was just the copy/replace that was the problem.
Top
Page 1 of 2 12>


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 581 anonymous users online.
Newest Members
Audio, Hoschi, Comet, rrosell, PatrickPinto
17880 Registered Users

Generated in 0.19 seconds in which 0.128 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org