none
adding an integer to an intptr RRS feed

  • Question

  • how can i add an integer to intptr in vb.NET (.NET version under 4.0), is there a method or a function for that?

    i know there is in .NET version 4.0 a shared function called Intptr.Add that does the work, but i am under .NET version 2.0

    the code is in its original format (C++):

    while (ret ) 
    {
            ret = ov_read(&vf, buf+pos, size-pos, 0, 2, 1, &sec); // buf = pointer, pos = integer

            pos += ret;
        }
    Monday, July 2, 2018 10:09 PM

All replies

  • Hi

    Not sure if this is of any help,but, here t is anyway:

        Dim ip As IntPtr = CType(12, IntPtr)
        ip += 1
        Console.WriteLine(ip)  '  result = 13
    


    Regards Les, Livingston, Scotland

    Monday, July 2, 2018 11:35 PM
  • Hi 

    I am not particularly clear about your statement. Do you want to add the Int type to the Intptr type? If so, you can use the IntPtr constructor.

            Dim ptr As IntPtr = New IntPtr(12)
            Console.WriteLine(ptr + 1)
            Console.ReadLine()

    Best Regards,

    Alex


    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.

    Tuesday, July 3, 2018 2:48 AM
    Moderator
  • In order to add buf with pos (i.e. IntPtr with Integer) in .NET 2.0, try ‘New IntPtr(buf.ToInt64 + pos)’.

    Tuesday, July 3, 2018 5:58 AM
  • Viorel_ , your answer is correct.
    Tuesday, July 3, 2018 8:46 AM
  • Hi

    I am glad you have got your solution. It would be appreciated if you could share us your solution and then mark it as an answer.

    Best Regards,

    Alex


    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, July 18, 2018 7:25 AM
    Moderator