Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Windows Installer API and C#

533 views
Skip to first unread message

Michel van Heijster

unread,
Feb 9, 2003, 3:07:00 PM2/9/03
to
I've spend my whole weekend trying to get the Windows Installer API working
in my C# application.

I can't even get the MsiGetProductCode function working; the lpProductBuf
string remains unchanged, but the function itselfs returns ERROR_SUCCESS.
I've verified that the component is correctly installed using MsiSpy.

Does anyone has a working example of the Windows Installer API in C#, or a
link to further reading???


Michael (michka) Kaplan [MS]

unread,
Feb 9, 2003, 9:14:03 PM2/9/03
to
Could you post your pinvokes? It is much easier to respond with a fix
if one can see the code that is failing. From your description, I
would guess that you defined the param as a string rather than a
StringBuilder.

--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.

"Michel van Heijster" <michel....@quicknet.nl> wrote in message
news:1044821200.51259@cache1...

Michel van Heijster

unread,
Feb 10, 2003, 1:50:29 AM2/10/03
to
Changing the lpProductBuf to a StringBuilder (new StringBuilder(39, 39) did
the trick for MsiGetProductCode, thanx! I had the same problems with other
functions as well, but I will try to update them later today to use
StringBuilders instead of strings.

"Michael (michka) Kaplan [MS]" <mic...@online.microsoft.com> wrote in
message news:epMJYoK0CHA.2600@TK2MSFTNGP11...

Michael Ballou

unread,
Feb 11, 2003, 8:35:19 PM2/11/03
to
Is it possible to get a .cs file from MS with all of the MSI API calls
defined with the proper pInvokes? I have all the ones I need working at the
moment, but since there is no managed wrapper yet and it's very difficult
(and also slow) to use the MSI COM Automation wrapper in .Net, it would be
nice to at least get a .cs file we can include in our projects for the
pInvoke.

Thanks,
Mike Ballou


"Michael (michka) Kaplan [MS]" <mic...@online.microsoft.com> wrote in
message news:epMJYoK0CHA.2600@TK2MSFTNGP11...

Michael (michka) Kaplan [MS]

unread,
Feb 12, 2003, 12:37:49 AM2/12/03
to
As far as I know, there is no such file, specifically. And also I
believe that some APIs can be called more than one way (so they would
need overrides).

But in truth nothing in MSI is all that complicated in terms of coming
up with the pinvokes.

And since no one project would ever need every function, including
*all* of them would be a huge mistake since it would bloat up your
project. Even if there was a big .cs file, you would want to
copy/paste stuff from it.


--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.


"Michael Ballou" <michael.ball...@wonderware.com> wrote in
message news:ePudzbj0CHA.2596@TK2MSFTNGP12...

Michel van Heijster

unread,
Feb 12, 2003, 2:38:14 PM2/12/03
to
Yes, I have another problem with the API. I'm trying to get the user's info
using MsiGetUserInfo, but I keep getting USERINFOSTATE_INVALIDARG as
returned value for the function.

<<WindowsInstaller.cs>>

[DllImport("msi")]
public extern static USERINFOSTATE MsiGetUserInfo(string szProduct,
StringBuilder lpUserNameBuf, uint pcchUserNameBuf, StringBuilder
lpOrgNameBuf, uint pcchOrgNameBuf, StringBuilder lpSerialBuf, uint
pcchSerialBuf);

<<frmSplashscreen.cs>>
System.Text.StringBuilder MsiProductCode = new System.Text.StringBuilder(39,
39);
DpcNederland.Win32.WindowsInstaller.MsiGetProductCode("{D0DB11A0-055B-42AE-B
427-C86ECB279F99}", MsiProductCode);

System.Text.StringBuilder MsiUsername = new System.Text.StringBuilder(0, 1);
System.Text.StringBuilder MsiOrganisation = new System.Text.StringBuilder(0,
1);
System.Text.StringBuilder MsiSerial = new System.Text.StringBuilder(0, 1);
uint pcchUserNameBuf = 0;
uint pcchOrgNameBuf = 0;
uint pcchSerialBuf = 0;

MessageBox.Show(DpcNederland.Win32.WindowsInstaller.MsiGetUserInfo(MsiProduc
tCode.ToString(), MsiUsername, pcchUserNameBuf, MsiOrganisation,
pcchOrgNameBuf, MsiSerial, pcchSerialBuf).ToString());

The MsiGetProductCode returns the correct ProductCode, so I don't think
that's the problem. Please help me!

"Michel van Heijster" <michel....@quicknet.nl> wrote in message

news:1044859811.644174@cache2...

Michael (michka) Kaplan [MS]

unread,
Feb 12, 2003, 6:57:04 PM2/12/03
to
There are a few problems here. For example, all of the "DWORD *"
params should be "ref uint" params. The API wants to return data and
you are not passing it an appropriate variable.


--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.

"Michel van Heijster" <michel....@quicknet.nl> wrote in message

news:1045078673.649312@cache2...

Rory Plaire

unread,
Feb 14, 2003, 1:02:30 PM2/14/03
to
MichKa,

Thanks for the insights so far!

You mentioned there are a few problems, but enumerated only one...
what are the others? I am having a difficult time (where is all the
good documentation on pinvoking?) getting functions that use pointers
to dwords which specify the size of string buffers to work...

I would be interested in the other issues you might have seen with the
listed code in this thread as well as more insight into the pcch...
type issues.

kindly,
-rory 8)


"Michael \(michka\) Kaplan [MS]" <mic...@online.microsoft.com> wrote in message news:<#4vUjJv0CHA.2308@TK2MSFTNGP09>...

Michael (michka) Kaplan [MS]

unread,
Feb 14, 2003, 1:32:57 PM2/14/03
to
I have not used that specific API from C#, I just listed the first
obvious one I saw. It should be represented with a ref type. If you
have tried this and it still fails, please post the code (I use thie
technique for other Msi APIs and it works just fine for me).


--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.


"Rory Plaire" <rory....@co.benton.or.us> wrote in message
news:28e92646.03021...@posting.google.com...

0 new messages