locked
[C#] unsafe functions in NetmonAPI.cs RRS feed

  • Question

  • Hi, I'm a C# developper.
    I'm making an Application to view HTTP traffics with WPF.
    There are several functions defined as 'unsafe'. I hate 'unsafe' , then I tried to re-define as 'safe' them , for example;
    unsafe public static extern UInt32 NmGetPropertyById( IntPtr hFrameParser , UInt32 ulPropertyId , UInt32 ulBufferSize , byte* pBuffer , out UInt32 ulReturnLength , out NmPropertyValueType ulType , UInt32 ulKeyCount , CNmPropertyStorageKey[] pKeyArray );
    -----> public static extern UInt32 NmGetPropertyById( IntPtr hFrameParser , UInt32 ulPropertyId , UInt32 ulBufferSize , byte[] pBuffer , out UInt32 ulReturnLength , out NmPropertyValueType ulType , UInt32 ulKeyCount , CNmPropertyStorageKey[] pKeyArray );
    
    


    And it seems working.

    Are there any troubles if they are defined as 'safe'?

     

    Wednesday, February 23, 2011 4:20 AM

Answers

  • Hi Mizutama,

    You should be alright, just be careful.  Our API is unmanaged and was not original designed with C# in mind.  We later created the wrapper as a convenience, but wanted to make sure people realized they're still working with unmanaged functions.

    As long as you're handling what you get back properly, you shouldn't have any many troubles.  I think we've seen a few cases where people have done this; you just have to make sure you convert them properly.  Otherwise the C# interop layer may not pass things back and forth correctly.


    Michael Hawker | Program Manager | Network Monitor
    • Marked as answer by Paul E Long Thursday, February 24, 2011 3:12 PM
    Wednesday, February 23, 2011 8:32 PM

All replies

  • Hi Mizutama,

    You should be alright, just be careful.  Our API is unmanaged and was not original designed with C# in mind.  We later created the wrapper as a convenience, but wanted to make sure people realized they're still working with unmanaged functions.

    As long as you're handling what you get back properly, you shouldn't have any many troubles.  I think we've seen a few cases where people have done this; you just have to make sure you convert them properly.  Otherwise the C# interop layer may not pass things back and forth correctly.


    Michael Hawker | Program Manager | Network Monitor
    • Marked as answer by Paul E Long Thursday, February 24, 2011 3:12 PM
    Wednesday, February 23, 2011 8:32 PM
  • Thanks a lot.
    Thursday, February 24, 2011 8:37 AM