Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How do I pass a byte array from C++ to VB.NET?

How do I pass a byte array from C++ to VB.NET?

Scheduled Pinned Locked Moved Visual Basic
c++data-structuresquestioncsharp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    prcarp
    wrote on last edited by
    #1

    I have a VB.NET 2005 application that makes calls to a VC++ (VC6) DLL and I have that part working fine. The C++ DLL makes use of callback functions to let the VB app know of unsolicited events and that works as well (the functions are at least being called). The problem is I don't know the proper parameters to use (either the C++ or VB side) to get a byte array from C++ back to VB. I have tried the following: C++ side: BYTE bArray[] = { 11, 12, 13, 14, 15 }; int len = 5; pfnCallback(bArray, len); VB side: CallbackHandler(ByVal data() as Byte, ByVal len as Integer) This resulted in the data array length of 1 and it only had the first value of the array no matter how big my array was. Then I tried: C++ side: SAFEARRAY *psa; (then properly created psa, and data copied in) pfnCallback(psa); (then properly destroy psa) VB side: CallbackHandler(ByVal data() as Byte) This resulted in the data array length of 1 and it had the first element of C's SAFEARRAY in it (cDim). I could not see my data. Am I barking up the wrong tree? Is what I want to do possible? I tried ByRef and got exception errors as it jumped from native code to managed code. Thanks in advance, Paul

    D 1 Reply Last reply
    0
    • P prcarp

      I have a VB.NET 2005 application that makes calls to a VC++ (VC6) DLL and I have that part working fine. The C++ DLL makes use of callback functions to let the VB app know of unsolicited events and that works as well (the functions are at least being called). The problem is I don't know the proper parameters to use (either the C++ or VB side) to get a byte array from C++ back to VB. I have tried the following: C++ side: BYTE bArray[] = { 11, 12, 13, 14, 15 }; int len = 5; pfnCallback(bArray, len); VB side: CallbackHandler(ByVal data() as Byte, ByVal len as Integer) This resulted in the data array length of 1 and it only had the first value of the array no matter how big my array was. Then I tried: C++ side: SAFEARRAY *psa; (then properly created psa, and data copied in) pfnCallback(psa); (then properly destroy psa) VB side: CallbackHandler(ByVal data() as Byte) This resulted in the data array length of 1 and it had the first element of C's SAFEARRAY in it (cDim). I could not see my data. Am I barking up the wrong tree? Is what I want to do possible? I tried ByRef and got exception errors as it jumped from native code to managed code. Thanks in advance, Paul

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      I think you're looking for this[^].

      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      P 1 Reply Last reply
      0
      • D Dave Kreskowiak

        I think you're looking for this[^].

        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        P Offline
        P Offline
        prcarp
        wrote on last edited by
        #3

        Perfect! :-D Thanks for the pointer. -P

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups