dear all,
I've a wrapper in C# for MSI API, (WindowsInstaller),
and i can do what i want very good, The question is
when I exit from my application, I found icannot exit,
the application was hold on. I think i don't release
none-managed resource.
But i have using CLoseHandler method
like :error = WindowsInstaller.MsiInterop.MsiCloseHandle(recordP);
error = WindowsInstaller.MsiInterop.MsiViewClose(viewP);
error = WindowsInstaller.MsiInterop.MsiCloseHandle(viewP);
error = WindowsInstaller.MsiInterop.MsiCloseHandle(ptr);
So i think i've close all handles, but why?
I must kill the procdure in task manager.
Anybody can give me some advice? thanks.
This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Using MSI database in C#
Started by
BlueTulip
, Jul 25 2006 06:53
6 replies to this topic
Posted 26 July 2006 - 06:25
Are you implementing the IDisposable interface and hence implement a Dispose() method? Are you also setting all COM objects to null/nothing? As far as I know this is the standard way to ensure correct cleanup of unmanaged resources in a deterministic, garbage collector independent way.
Edited by Glytzhkof, 26 July 2006 - 06:29.
Regards
-Stein Åsmul
-Stein Åsmul
Posted 26 July 2006 - 10:50
thanks Glytzhkof, I've got the reson,
In fact I've release all Handle.
But when transform parameter to native COM method,
the data type maybe were not like you imagin.
e.g.
a com method need a parameter Char*,
but you must transform a string (ref string)by wrapper to the COM method,
when call end. You got a string, but this string is not C# string,
although it was declared as string in C#,
i can got this string's value, but if i check this string's length,
use string.Length, i got 0, it's so strange,
but in fact it's length is not 0, because it has value.
and on other hand , you cannot use + operator and other
string method.
So in fact this string is just a pointer, and this pointer point
to a memory address, and this string isnot end with
endflag. So it's lenght always 0, but it has value.
So when you exit you application,
the .net gc cannot collect the memory allcated by COM method.
so it looks down.
The result is i release the pointer, it will be OK,
if you don't use C#, may be i cannot make me understood:)
thanks
In fact I've release all Handle.
But when transform parameter to native COM method,
the data type maybe were not like you imagin.
e.g.
a com method need a parameter Char*,
but you must transform a string (ref string)by wrapper to the COM method,
when call end. You got a string, but this string is not C# string,
although it was declared as string in C#,
i can got this string's value, but if i check this string's length,
use string.Length, i got 0, it's so strange,
but in fact it's length is not 0, because it has value.
and on other hand , you cannot use + operator and other
string method.
So in fact this string is just a pointer, and this pointer point
to a memory address, and this string isnot end with
endflag. So it's lenght always 0, but it has value.
So when you exit you application,
the .net gc cannot collect the memory allcated by COM method.
so it looks down.
The result is i release the pointer, it will be OK,
if you don't use C#, may be i cannot make me understood:)
thanks
Posted 26 July 2006 - 22:18
This makes some sense, though it is indeed strange. I guess the implication here is that C# is not the best language to use in MSI for several reasons: 1) it requires the .NET framework which may not be available, 2) Using COM Interop is clunky and error pronoe, 3) Using unmanaged resources from C# is also risky, especially if you don't implement the IDisposable interface and provide proper cleanup there (since the garbage collector may not be run immediately as resources go out of scope).
Regards
-Stein Åsmul
-Stein Åsmul
Posted 27 July 2006 - 02:09
Your are right, of course C# is not the best choice,
but 1) I just do a job for my boss :-(
2) This is just integrated with a application written C#,
I've no choice.
but 1) I just do a job for my boss :-(
2) This is just integrated with a application written C#,
I've no choice.
Posted 03 August 2006 - 23:16
Have you seen:
"C# Wrappers for the Windows Installer API"
http://www.installsi...en/msi/tips.htm
With a link to SourceForge
"C# Wrappers for the Windows Installer API"
http://www.installsi...en/msi/tips.htm
With a link to SourceForge
Christopher Painter, MCSE
Author of:
DeploymentEngineering.com
MSI Factory Provider for ADO.NET 2.0 (Work In Progress)
99 Bottles Of Beer - Windows Installer
PM for personal communication only. Please ask questions in the forums.
Author of:
DeploymentEngineering.com
MSI Factory Provider for ADO.NET 2.0 (Work In Progress)
99 Bottles Of Beer - Windows Installer
PM for personal communication only. Please ask questions in the forums.
Posted 18 July 2012 - 12:51
QUOTE (chrpai @ 2006-08-03 23:16) |
Have you seen: "C# Wrappers for the Windows Installer API" http://www.installsi...en/msi/tips.htm With a link to SourceForge |
Note that version 1.1 of these extremely useful wrappers doesn't work, to get a correct version get the SVN trunk tarball : http://izfree.svn.so...terop/?view=tar