Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / May 2004

Tip: Looking for answers? Try searching our database.

Error when calling msi native apis

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Faltys - 26 May 2004 00:16 GMT
The code snippet below was simplified from a much larger application.  I can run against several other functions in Msi.dll without problems.  However, I am running into a problem when executing against the MsiGetSummaryInformation function.  I get the exception "Object reference not set to an instance of an object" when calling the function.  I have tried everything that I can think of.  What am I missing?

Thanks
Mik

using System
using System.Runtime.InteropServices

namespace SimpleTestIns

    /// <summary
    /// Summary description for Class1
    /// </summary
    class Class
   
        /// <summary
        /// The main entry point for the application
        /// </summary
        ///

        [DllImport("msi.dll")
        private static extern uint MsiGetSummaryInformation(ulong dbhandle,string path,uint updateCount,ref ulong infoHandle)

        public void Test(
       
            ulong aHandle = 0
            uint rc = MsiGetSummaryInformation(0,null,19,ref aHandle)
            Console.WriteLine("Executed successfully.")
       

        [STAThread
        static void Main(string[] args
       
            tr
           
                Class1 c1 = new Class1()
                c1.Test()
           
            catch(Exception e
           
                Console.WriteLine("\r\n\r\n ERROR MESSAGE: "+e.Message+"\r\n\r\n"+e.StackTrace)
           
       
   

ERROR

ERROR MESSAGE: Object reference not set to an instance of an object

  at SimpleTestInst.Class1.MsiGetSummaryInformation(UInt64 dbhandle, String pa
h, UInt32 updateCount, UInt64& infoHandle
  at SimpleTestInst.Class1.Test() in d:\hh3-new\rsr-rel1\ingen\build\net\test\
estmsi\simpletestinst\class1.cs:line 2
  at SimpleTestInst.Class1.Main(String[] args) in d:\hh3-new\rsr-rel1\ingen\bu
ld\net\test\testmsi\simpletestinst\class1.cs:line 3
Phil Wilson - 26 May 2004 01:19 GMT
What happens if you actually give it a string that it's expecting instead of
a null?
Signature

Phil Wilson [MVP Windows Installer]
----

> The code snippet below was simplified from a much larger application.  I can run against several other functions in Msi.dll without problems.
However, I am running into a problem when executing against the
MsiGetSummaryInformation function.  I get the exception "Object reference
not set to an instance of an object" when calling the function.  I have
tried everything that I can think of.  What am I missing?

> Thanks,
> Mike
[quoted text clipped - 50 lines]
>    at SimpleTestInst.Class1.Main(String[] args) in d:\hh3-new\rsr-rel1\ingen\bui
> ld\net\test\testmsi\simpletestinst\class1.cs:line 33
Mike Faltys - 26 May 2004 01:31 GMT
Same error.  I have tried to pass the location of the msi database.  I have also attempted to change the string to an uint and pass 0 and also the valid memory location of a string.  All have yielded the "Object reference not set to an instance of an object".

Thanks,
Mike
Phil Wilson - 26 May 2004 01:46 GMT
Ok, it's not the string, it's that the handles need to be IntPtr, and you
haven't allocated one for the first parameter:

[DllImport("msi")]
private static extern uint MsiGetSummaryInformation(IntPtr dbhandle,string
path,uint updateCount,ref IntPtr infoHandle);
public void Test()
{
IntPtr inh = new IntPtr(0); // Should be a real handle even if it's empty
IntPtr aHandle = IntPtr.Zero;
uint rc = MsiGetSummaryInformation(inh,"this",19,ref aHandle); // gets 1620
when you don't have the file path
Console.WriteLine("Executed successfully.");
}

Signature

Phil Wilson [MVP Windows Installer]
----

> Same error.  I have tried to pass the location of the msi database.  I have also attempted to change the string to an uint and pass 0 and also the
valid memory location of a string.  All have yielded the "Object reference
not set to an instance of an object".

> Thanks,
> Mike
MikeFaltys - 27 May 2004 01:46 GMT
Thanks, that worked.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.