From: John Whitworth on
Hi,

I'm trying to retrieve the ProductID for my application via MSI.dll, using
the following code (after assistance from the dotnet.general NG):

Declare Auto Function MsiGetProductInfo Lib "msi.dll" (ByVal product As
String, ByVal [property] As String, ByVal valueBuf As String, ByRef len As
Long) As Long

..
..

Public ProdID = New String(" ", 255)
Public RegOwn = New String(" ", 255)
Public ProdIDLen As Long = 255
Public RegOwnLen As Long = 255

Private Sub MainForm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim dummy As Long

dummy = MsiGetProductInfo("{9459583F-02E4-4971-B3B7-E2235F41F477}",
"ProductID", ProdID, ProdIDLen)
dummy = MsiGetProductInfo("{9459583F-02E4-4971-B3B7-E2235F41F477}",
"RegOwner", RegOwn, RegOwnLen)

MsgBox("Product ID: " & Mid(ProdID, 1, ProdIDLen))
MsgBox("Regd Owner: " & Mid(RegOwn, 1, RegOwnLen))

..
..

At one point, I actually had this working - but now it has failed again,
returning empty strings - and I'm not sure what I did wrong. I can see the
ProductID in the installation keys within the registry.

I've tried it with and without the 'dummy' field. And I've experimented with
int32 and long in the Declare statement, to no avail. The application is
installed on my desktop machine.

Any suggestions gratefully received.

Thanks

John

From: Armin Zingler on
John Whitworth schrieb:
> Hi,
>
> I'm trying to retrieve the ProductID for my application via MSI.dll, using
> the following code (after assistance from the dotnet.general NG):
>
> Declare Auto Function MsiGetProductInfo Lib "msi.dll" (ByVal product As
> String, ByVal [property] As String, ByVal valueBuf As String, ByRef len As
> Long) As Long

Wrong declaration.

UINT MsiGetProductInfo(
__in LPCTSTR szProduct,
__in LPCTSTR szProperty,
__out LPTSTR lpValueBuf,
__inout DWORD *pcchValueBuf
);

UINT = unsigned int = UInt32 = UInteger
DWORD = 32-bit unsigned integer = UInt32 = UInteger

Also try attaching the MarshalAsAttribut(System.Runtime.InteropServices.UnmanagedType.LPTStr)


--
Armin

From: John Whitworth on


"Armin Zingler" <az.nospam(a)freenet.de> wrote in message
news:#yFDrRgkKHA.2188(a)TK2MSFTNGP04.phx.gbl...
> John Whitworth schrieb:
>> Hi,
>>
>> I'm trying to retrieve the ProductID for my application via MSI.dll,
>> using
>> the following code (after assistance from the dotnet.general NG):
>>
>> Declare Auto Function MsiGetProductInfo Lib "msi.dll" (ByVal product
>> As
>> String, ByVal [property] As String, ByVal valueBuf As String, ByRef len
>> As
>> Long) As Long
>
> Wrong declaration.
>
> UINT MsiGetProductInfo(
> __in LPCTSTR szProduct,
> __in LPCTSTR szProperty,
> __out LPTSTR lpValueBuf,
> __inout DWORD *pcchValueBuf
> );
>
> UINT = unsigned int = UInt32 = UInteger
> DWORD = 32-bit unsigned integer = UInt32 = UInteger
>
> Also try attaching the
> MarshalAsAttribut(System.Runtime.InteropServices.UnmanagedType.LPTStr)
>

Spot on! Thanks Armin!

Declare Auto Function MsiGetProductInfo Lib "msi.dll" (ByVal product As
String, ByVal [property] As String, <MarshalAs(UnmanagedType.LPTStr)> ByVal
valueBuf As String, ByRef len As UInteger) As UInteger