Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 2

freeing up CoCreateObjectDotNet or removing reference

Jump to solution


I am calling a .Net function inside a dll that is unpacked into the SUPPORTDIR folder.

I noticed that if CoCreateObjectDotNet() is called, that dll would not be deleted from SUPPORTDIR after installation ends.

Then, if I purposely don't call CoCreateObjectDotNet(), that dll is automatically deleted FROM SUPPORTDIR after installation. Which leads me to suspect that I might not be freeing up the object correctly. Here is my code below.

The documentation also mentions to use CoFreeLibrary(), however, I cannot use it as it's causing Build errors.

set oLib=CoCreateObjectDotNet(szDLLpath,"DllName.ClassName");
ret = oLib.MyMethod(param);

set oLib= NOTHING; // this is not enough apparently.

Looking forward to an answer for this issue.

Thank you!


0 Kudos
(1) Solution
Flexera Alumni
(2) Replies
Flexera Alumni

Hi @remondo ,


I could see "CoCreateObjectDotNet" function is deprecated in IS2014 onwards,how about using "DotNetCoCreateObject"?

What are the build error you get on using  CoFreeLibrary()?



Thank you for your reply Jennifer! You have pointed me to the right direction.

I am using Installshield 2016.

1. Regarding CoFreeLibrary(), it's my mistake, I forgot to declare the prototype


prototype void ole32.CoFreeLibrary( byval int );

In order to call CoFreeLibrary(), I need to get the handle to the dll.

So I needed to call GetModuleHandle() first to get the handle. It didn't work.

2. I also tried the UseDLL() and UnUseDLL();

Didn't work.

Caveat: UnUseDLL()'s parameter according to the documentation should not include the path.

UseDLL() needs the path though.

3. DotNetCoCreateObject()

So I had to specify a temporary app domain name, then call DotNetUnloadAppDomain() afterwards.

This worked! Smiley Very Happy

set oLib=DotNetCoCreateObject(szDLLpath,"MyDLLName.MyClassName", "tempdomain");

retDotNet = oLib.MyCSharpMethod();

retDotNet = DotNetUnloadAppDomain("tempdomain"); // returns 0


0 Kudos