none
I get an exception in PInvoke enumerate volume. Why? RRS feed

  • Question

  • This is the code:

      public void EnumerateVolume (out Dictionary<UInt64, FileNameAndFrn> files, string[ ] fileExtensions )
            {
                files = new Dictionary<ulong, FileNameAndFrn> ( );
                IntPtr medBuffer = IntPtr.Zero;
                try
                {
                    GetRootFrnEntry ( );
                    GetRootHandle ( );
                    CreateChangeJournal ( );
                    SetupMFT_Enum_DataBuffer ( ref medBuffer );
                    EnumerateFiles ( medBuffer, ref files, fileExtensions );
                }
    
                catch ( Exception e )
                {
                    Console.WriteLine ( e.Message, e );
                    Exception innerException = e.InnerException;
                    while ( innerException != null )
                    {
                        Console.WriteLine ( innerException.Message, innerException );
                        innerException = innerException.InnerException;
                    }
                    throw new ApplicationException ( "Error in EnumerateVolume()", e );  // Exception here
                }
                finally
                {
                    if ( _changeJournalRootHandle.ToInt32 ( ) != PInvokeWin32.INVALID_HANDLE_VALUE )
                    {
                        PInvokeWin32.CloseHandle ( _changeJournalRootHandle );
                    }
                    if ( medBuffer != IntPtr.Zero )
                    {
                        Marshal.FreeHGlobal ( medBuffer );
                    }
                }
            }                                               // EnumerateVolume

    It also said "Arithmetical operation resulted in an overflow."

    - MyCatAlex

     
    • Edited by MyCatAlex Sunday, December 9, 2018 11:22 PM
    Sunday, December 9, 2018 11:12 PM

All replies

  • You go with an inner.exception message. Why don't you get the stack trace  and display more about the exception. I am not saying dump the entire stack trace into the post, but post key sections of the stack trace.
    Monday, December 10, 2018 1:35 AM
  • Hi MyCatAlex,

    Thank you for posting here.

    For your question, first, there are some methods, variables defined by yourself, I could not test your code. It would be better to provide the details of your error message. 

    We are waiting for your update.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 10, 2018 2:12 AM
    Moderator
  • Hi there,

    I finally got an image of the exception

    And I got a StackTrace:

    Please keep in mind that all objects beginning with "push" are in fact buttons on the surface of a form.

    System.ApplicationException
      HResult=0x80131600
      Message=Error in EnumerateVolume()
      Source=ComeAndGet
      StackTrace:
       at ComeAndGet.PInvokeWin32.EnumerateVolume(Dictionary`2& files, String[] fileExtensions) in C:\VCSharp_Projects\ComeAndGet\ComeAndGet\MasterRecordRead.cs:line 239
       at ComeAndGet.PInvokeWin32.MainWWWW(String ext) in C:\VCSharp_Projects\ComeAndGet\ComeAndGet\MasterRecordRead.cs:line 206
       at ComeAndGet.Form1.pushMasterRecordRead_pg8_Click(Object sender, EventArgs e) in C:\VCSharp_Projects\ComeAndGet\ComeAndGet\Form1.cs:line 7526
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at ComeAndGet.Program.Main() in C:\VCSharp_Projects\ComeAndGet\ComeAndGet\Program.cs:line 16
    
    Inner Exception 1:
    OverflowException: Arithmetic operation resulted in an overflow.

    Thanks, - MyCatAlex


    • Edited by MyCatAlex Monday, December 10, 2018 6:06 PM
    Monday, December 10, 2018 6:02 PM
  • I also will try to explain the transformation from Windows Forms Form to Windows Console application.

    I designed this C# application as Windows Forms application but then I realized that I cannot use Console. I kept posting here but nobody came up with any reasonable suggestion. I don't remember now if it was my idea or someone else's. This is what I did. I went to Project properties and changed Windows Forms application to Windows Console application. Now I can use Console (for debug) and I have my form.

    Thanks, - MyCatAlex

    Monday, December 10, 2018 6:15 PM
  • This application, whether designed by me or copied somewhere, was written when the volumes of hard disks were much smaller. Now they are 10 times or more larger.

    - MyCatAlex

    Monday, December 10, 2018 7:18 PM
  • Hi MyCatAlex,

    Thank you for feedback.

    Why do you throw an exception in Catch? Which line of the code you get the error? Sorry for that, I still do not understand what you want.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 12, 2018 7:22 AM
    Moderator
  • Wendy hi,

    If you don't understand what I want after I posted so much code, partially at your request, it means you cannot help me.

    This code is designed to read raw memory in the files.

    Friday, December 14, 2018 5:05 PM
  • I checked medBuffer. The value was "0x000002029b0246e0" = (2,210,213,807,840)<sub>10</sub>

    It is far from overflow. The object is Toshiba's External hard drive, full of files. It has 447 gb out of 931 gb free.

    What is the problem?

    Thanks, - MyCatAlex




    • Edited by MyCatAlex Saturday, December 15, 2018 4:36 PM
    Friday, December 14, 2018 10:17 PM
  • Hi MyCatAlex,

    The code you provided could not show it is used to read raw memory in the files.

    Based on my search, the code you provided is from the link below.

    https://code.msdn.microsoft.com/windowsdesktop/CCS-LABS-C-Accessing-the-d317805c/view/Discussions#content

    If yes, do you do any change of the sample code?

    Based on my test of the sample, everything is ok. There is nothing wrong with code. 

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 19, 2018 8:08 AM
    Moderator
  • You have a numeric value that rolled over from positive to negative because it was too big. That is the error. The inner exception should have a stack trace. That stack trace should identify the line of code where the rollover occurred. Please post that code. It is being called from your MasterRecordRead.cs line 239 but that is the extent we can see.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, December 19, 2018 3:58 PM
    Moderator