none
converting a C# code to vb.NET RRS feed

  • Question

  • please convert to me this sample of code to vb.NET:

    the native C++ sample:

    int ogg_decode_one_vorbis_packet(void* vf_ptr, void* buf_out, int buf_byte_size,
                                             int ogg_sample_size,
                                             int* channels_cnt, int* sampling_rate,
                                             int* err_ov_hole_cnt, int* err_ov_ebadlink_cnt)

    the C#.NET sample is:

     [DllImport("TgPlayOgg_vorbisfile.dll", CallingConvention=CallingConvention.Cdecl)]
            public unsafe static extern int ogg_decode_one_vorbis_packet(
                void* vf_ptr, void* buf_out, int buf_byte_size, 
    int bits_per_sample, int* channels_cnt, int* sampling_rate, 
    int* err_ov_hole_cnt, int* err_ov_ebadlink_cnt);

    Friday, June 29, 2018 6:22 PM

All replies

  • Hi

    Google is your friend - search for 'Convert C++'


    Regards Les, Livingston, Scotland

    Friday, June 29, 2018 6:29 PM
  • i have tried several example of converters but always it gives me AccessViolationException error.
    Friday, June 29, 2018 7:05 PM
  • This is what the P/Invoke Interop Assistant tool converts the C++ signature to,  for Vb.Net.

        <DllImport("TgPlayOgg_vorbisfile.dll", CallingConvention:=CallingConvention.Cdecl)>
        Public Shared Function ogg_decode_one_vorbis_packet(ByVal vf_ptr As IntPtr, ByVal buf_out As IntPtr, ByVal buf_byte_size As Integer, ByVal ogg_sample_size As Integer, ByRef channels_cnt As Integer, ByRef sampling_rate As Integer, ByRef err_ov_hole_cnt As Integer, ByRef err_ov_ebadlink_cnt As Integer) As Integer
        End Function
    



    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Friday, June 29, 2018 7:13 PM
    Friday, June 29, 2018 7:12 PM
  • to IronRazerz: it gives me an Accessviolationexception

    i have another point : i did not allocate any memory space for the 2 last parameters. did that interfer with the result (so with the error)?

    Friday, June 29, 2018 7:59 PM
  • to IronRazerz: it gives me an Accessviolationexception

    i have another point : i did not allocate any memory space for the 2 last parameters. did that interfer with the result (so with the error)?

     What is the full exception message that you get?

      The error may or may not be due to the api function being wrong,  it very well could be that you are using it wrong or maybe passing the wrong data types to the function.  There is a number of different possibilities that could be causing the exception.

     Also,  make sure that you have Option Strict and Option Explicit turned on so that you are sure that you have everything declared as the correct data types in your code.

      I have declared and used loads of api functions but,  I never used this api function and know nothing about how it is suppose to be used.  Perhaps you need to look through all of the (C#) code in the downloadable (Source Files) at the link below and see how they have used it.  C# is similar enough to Vb.Net that you should be able to follow what they do and how they use the function.

    Loading Ogg Vorbis Files from Memory in .NET


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Friday, June 29, 2018 8:34 PM
    Friday, June 29, 2018 8:33 PM
  • you are right, i have fixed it by changing the first parameter.
    Friday, June 29, 2018 8:55 PM
  • you are right, i have fixed it by changing the first parameter.

     Glad you got if fixed.

     If your question has been answered,  please don't forget to mark the post or post(s) that answered it as the answer(s).  Thanks.  8)


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Friday, June 29, 2018 9:05 PM
    Friday, June 29, 2018 9:05 PM