Red Gate forums :: View topic - Regarding MsiDatabaseCommit in Msi.dll
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
PInvoke.Net
PInvoke.Net forum

Regarding MsiDatabaseCommit in Msi.dll

Search in PInvoke.Net forum
Post new topic   Reply to topic
Jump to:  
Author Message
milindsm



Joined: 12 Mar 2010
Posts: 2

PostPosted: Fri Mar 12, 2010 12:06 pm    Post subject: Regarding MsiDatabaseCommit in Msi.dll Reply with quote

Hello,

I am using this method

Code:
[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:
[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
Back to top
View user's profile Send private message
Paul.Martin



Joined: 03 Feb 2010
Posts: 83
Location: Cambridgeshire

PostPosted: Fri Mar 12, 2010 7:55 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
milindsm



Joined: 12 Mar 2010
Posts: 2

PostPosted: Mon Mar 15, 2010 6:56 am    Post subject: Reply with quote

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

Code:

        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
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group