Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / May 2004

Tip: Looking for answers? Try searching our database.

Win32 Interop: Windows Installer SDK

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shane Warren - 30 Apr 2004 22:58 GMT
I need to determine the ProductCode from msi (install file) using a .net
application (web service) written in C#.  I found a function in the Windows
Installer SDK which seems to be what i want the function is defined as:

UINT MsiOpenDatabase(
 LPCTSTR szDatabasePath,
 LPCTSTR szPersist,
 MSIHANDLE* phDatabase
);

Mostly this isn't too tricky I defined an DLLInport for the function like:

[DllImport("msi.dll", CharSet=CharSet.Auto)]
public static extern int MsiOpenDatabase(String strDatabasePath, String
strPersist, out UInt32 hDatabase);

The tricky part is the szPersist parameter has some interesting preset
params I need to pass in that are defined as follows (from MsiQuery.h):

#define MSIDBOPEN_READONLY     (LPCTSTR)0  // database open read-only, no
persistent changes
#define MSIDBOPEN_TRANSACT     (LPCTSTR)1  // database read/write in
transaction mode
...etc...

I need to pass in the MSIDBOPEN_READONLY as the szPersist parameter, thats
where I'm a bit fuzzy on what should be done since that technically is a
string parameter but is being used as both string (for specifiying a path)
or a number (for specifying a mode), how does .net win32 interop deal with
this?

I've tried passing empty strings and null (which in my mind seems right),
but when the function is called it returns a successful return code (0) but
the handle returned is bogus (1, which strangely counts up by one each time
I call the MsiOpenDatabase function).  I can't use the returned handle in
any of the functions that expect a handle (I get an error code 6, which is
"Handle is invalid").
Phil Wilson - 01 May 2004 01:03 GMT
Try multiple declarations for the different signatures. In your case you
need this kind of thing:

[DllImport("msi", EntryPoint="MsiOpenDatabase")]
public static extern int MsiOpenDatabaseX (string dbpath, IntPtr persist,
ref IntPtr msihandle);
.....
IntPtr hand=IntPtr.Zero;
IntPtr persist = new IntPtr(1);
int res = CallMsi.MsiOpenDatabaseX ("setup1.msi", persist, ref hand);
Signature

Phil Wilson [MVP Windows Installer]
----

> I need to determine the ProductCode from msi (install file) using a .net
> application (web service) written in C#.  I found a function in the Windows
[quoted text clipped - 33 lines]
> any of the functions that expect a handle (I get an error code 6, which is
> "Handle is invalid").

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.