Regarding MsiDatabaseCommit in Msi.dll

Announcements and discussion for PInvoke

Moderators: Luke Jefferson, Robert

Regarding MsiDatabaseCommit in Msi.dll

Postby milindsm » Fri Mar 12, 2010 12:06 pm

Hello,

I am using this method

Code: Select all
[DllImport("Msi.dll")]
static extern
UInt32 MsiDatabaseCommit(IntPtr hDatabase);


While calling this method, it throws an exception as "Attempt to read/write protected memory. Memory could be corrupt". I tried changing it to,

Code: Select all
[DllImport("Msi.dll")]
static extern unsafe
UInt32 MsiDatabaseCommit(IntPtr hDatabase);


But no luck. This occurs randomly. If I run the project from Visual Studio, it never occurs. Urgent help needed...!!!!
Regards,
MSM
milindsm
 
Posts: 2
Joined: Fri Mar 12, 2010 11:59 am

Postby Paul.Martin » Fri Mar 12, 2010 7:55 pm

Could you tell me what other operations you are doing on the MSI Database object?

I can't replicate the problem at all with a simple open, query, change and commit alogrithm. It does seems really strange that it works in Visual Studio hosting but not always outside of it. The two usual culprits for a program that works differently in VS than in real life are permissions or more frequently timing issues. Is your application multi-threaded?
Paul.Martin
 
Posts: 83
Joined: Wed Feb 03, 2010 11:20 am
Location: Cambridgeshire

Postby milindsm » Mon Mar 15, 2010 6:56 am

I am using most of the APIs to manipulate MSI database like

Code: Select all
        enum DATABASEOPENMODE
        {
            MSIDBOPEN_READONLY = 0,
            MSIDBOPEN_TRANSACT = 1,
            MSIDBOPEN_DIRECT = 2,
            MSIDBOPEN_CREATE = 3,
            MSIDBOPEN_CREATEDIRECT = 4
        }
       
        [DllImport("Msi.dll")]
        static extern unsafe UInt32 MsiOpenDatabase(
                                            string szDatabasePath,
                                            IntPtr pPersist,
                                            out IntPtr hDatabase);

        [DllImport("Msi.dll", ExactSpelling = true)]
        static extern UInt32 MsiCloseHandle(IntPtr pHandle);

        [DllImport("Msi.dll", CharSet = CharSet.Unicode)]
        static extern UInt32 MsiDatabaseOpenView(
                                                IntPtr hDatabase,
                                                [MarshalAs(UnmanagedType.LPWStr)] string szQuery,
                                                out IntPtr hView);

        [DllImport("Msi.dll", SetLastError = true)]
        static extern UInt32 MsiEnableUIPreview(
                                                IntPtr hDatabase,
                                                out IntPtr hPreview);

        [DllImport("Msi.dll", SetLastError = true)]
        static extern UInt32 MsiPreviewDialog(
                                                IntPtr hPreview,
                                                string szDialogName);

        [DllImport("Msi.dll", CharSet = CharSet.Unicode)]
        static extern UInt32 MsiViewExecute(
                                        IntPtr hView,
                                        IntPtr hRecord);

        [DllImport("Msi.dll", CharSet = CharSet.Unicode)]
        static extern UInt32 MsiViewFetch(
                                        IntPtr hView,
                                        out IntPtr hRecord);

        [DllImport("Msi.dll", CharSet = CharSet.Unicode)]
        static extern UInt32 MsiRecordGetString(
                                                IntPtr hRecord,
                                                int iField,
                                                [Out] StringBuilder szValueBuf,
                                                ref int pcchValueBuf);

        [DllImport("Msi.dll", ExactSpelling = true)]
        static extern long MsiRecordGetInteger(
                                                IntPtr hRecord,
                                                int iField);

        [DllImport("Msi.dll")]
        static extern unsafe UInt32 MsiDatabaseCommit(
                                                IntPtr hDatabase);

        [DllImport("Msi.dll", ExactSpelling = true)]
        static extern UInt32 MsiRecordReadStream(
                                                    IntPtr hRecord,
                                                    int iField,
                                                    [Out] byte[] szDataBuf,
                                                    ref int pcbDataBuf);

        [DllImport("Msi.dll", ExactSpelling = true)]
        static extern int MsiViewClose(IntPtr hView);


It is not a multi-threaded application. I am using Visual Studio 2008.
Regards,
MSM
milindsm
 
Posts: 2
Joined: Fri Mar 12, 2010 11:59 am


Return to PInvoke.Net

Who is online

Users browsing this forum: No registered users and 1 guest