Not in C# but simple old VBScript (but does work). When I was first
implementing this it took a bit of bashing/googling to get it to work.
What's particular odd is the record seems to need to be 3 fields, but the
only the first and third fields are used. Also the error template just needs
to be very simple "[3]" (presumably the 3 refers to the 3rd field of the
record).

Note that I recently found an odd problem with the
EnsureSimpleErrorMsgTemplate call and replaced it with a simple <Error
Id="32000">[3]</Error>.

Rob

'
' Display a message box
'   - buttons: vbOKOnly, vbOKCancel, vbAbortRetryIgnore, vbYesNoCancel,
vbYesNo, vbRetryCancel 
'   - icon: vbCritical, vbQuestion, vbExclamation, vbInformation
'   - Using icon vbCritical uses msiMessageTypeError, 
'                vbExclamation uses msiMessageTypeWarning,
'                vbQuestion or vbInformation is msiMessageTypeUser
'   - Common errors when calling this routine is to incorrectly specify 
'     the type of button (do not use vbOK.. it's vbOKOnly). Also incorrectly
'     specifying the icon causes problems (do not use vbOkOnly + vbError, as
'     vbError is not a valid icon).
'
Function MsiMsgBox(Message, Buttons)
    dim MessageType
    dim r

    '
    ' Make sure error #32000 exists (template of "[3]")
    '
    call EnsureSimpleErrorMsgTemplate()

    '
    ' The record to pass
    '
    set r = Session.Installer.CreateRecord(3)
    r.IntegerData(1) = 32000
    r.StringData(3) = Message

    '
    ' Figure out the type of message
    ' 
    if (Buttons and vbCritical) = vbCritical then
        MessageType = msiMessageTypeError + (Buttons and 15)
    elseif (Buttons and vbExclamation) = vbExclamation then
        MessageType = msiMessageTypeWarning + (Buttons and 15)
    else
        MessageType = msiMessageTypeUser + (Buttons and 15)
    end if
    
    '
    ' Display the message, return whatever button the user clicked
    '    
    MsiMsgBox = Session.Message(MessageType, r)
End Function


'
' EnsureSimpleErrorMsgTemplate
'  - Add error #32000 to the Errors table with a simple
'    template of "[3]". This allows a call to Session.Message
'    to display any text.
'
Sub EnsureSimpleErrorMsgTemplate()
    '
    ' For now just assume the Error record exists
    '   - Under Win2008 msi 4.5.6001.22162 the OpenView call would always
    '     throw an error, #0x80004005, with a description of "Database".
    '   TODO: At some point this needs to be more fully investigated.
    '
    exit sub
    
    Dim query
    Dim view
    dim record

    Query = "SELECT `Error` FROM `Error` WHERE `Error` = 32000"
    set view = Session.Database.OpenView(Query)
    View.Execute
    set Record = View.Fetch

    if Record is Nothing then
        query = "INSERT INTO `Error` (`Error`, `Message`) VALUES (32000,
'[3]') TEMPORARY "
        set view = Session.Database.OpenView(query)
        view.Execute
    end if
End Sub




------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to