Click here to Skip to main content
15,890,982 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I convert this to VB.net


[DllImport("msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
  static unsafe extern IntPtr memcpy(byte* dest, byte* src, uint count);

  /*
   * Callback function which copies the received data into the buffer and sets an event after the specified profiles
   */
   static unsafe void ProfileEvent(byte* data, uint uiSize, uint uiUserData)
     {
          if (uiSize > 0)
          {
              if (uiReceivedProfileCount < uiNeededProfileCount)
              {
                  //If the needed profile count not arrived: copy the new Profile in the buffer and increase the recived buffer count
                  uiProfileDataSize = uiSize;
                  // Copy the unmanaged data buffer (data) into the application
                  fixed (byte* dst = &abyProfileBuffer[uiReceivedProfileCount * uiSize])
                  {
                      memcpy(dst, data, uiSize);
                  }
                  uiReceivedProfileCount++;
              }

              if (uiReceivedProfileCount >= uiNeededProfileCount)
              {
                  //If the needed profile count is arived: set the event
                  hProfileEvent.Set();
              }
          }
      }


What I have tried:

Using CodeTranslator: Code Translation From VB.NET <-> C# <-> TypeScript <-> Java[^]

Comes up with:
Private Declare Function memcpy Lib "msvcrt.dll" Alias "memcpy" (ByVal dest As Byte, ByVal src As Byte, ByVal count As UInteger) As IntPtr

Private Shared Sub ProfileEvent(ByVal data As Byte, ByVal uiSize As UInteger, ByVal uiUserData As UInteger)
    If (uiSize > 0) Then
        If (bProfileReceived < uiNeededProfileCount) Then
            uiProfileDataSize = uiSize
            abyProfileBuffer((bProfileReceived * uiSize))
            memcpy(dst, data, uiSize)
            bProfileReceived = (bProfileReceived + 1)
        End If

        If (bProfileReceived >= uiNeededProfileCount) Then
            'If the needed profile count is arrived: set the event
            hProfileEvent.Set
        End If

    End If

End Sub


Honestly, it didn't do so well.

It missed the byte* array all together.

In reality I think I'm just stuck on:
fixed (byte* dst = &abyProfileBuffer[uiReceivedProfileCount * uiSize])
                   {
                       memcpy(dst, data, uiSize);
                   }


I googled
"fixed (byte*" vb.net


And found:
Convert fixed and byte* from c# to vb.net - Stack Overflow[^]

and I eventually found:
https://social.technet.microsoft.com/wiki/contents/articles/24254.moving-memory-in-net-using-vb-and-the-cil.aspx[^]
Not sure how to use that.

Any help to fill in the puzzle pieces?
Posted
Updated 26-Jan-19 4:35am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900