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. C / C++ / MFC
  4. How do I pass a byte array from VC++ to VB?

How do I pass a byte array from VC++ to VB?

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structuresquestioncsharp
4 Posts 3 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

    First, my apologies for posting this again - it went unanswered in the VB forum so I am trying with a bigger audience here.... I have a VB.NET 2005 application that makes calls to a C/C++ (VC6) DLL and I have that part working fine. The C/C++ DLL makes use of callback functions to let the VB application 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. For the short term, I made a string showing the hexadecimal values of the byte array and passed the string from the C/C++ library back up to VB; that works fine for now.... Thanks in advance, Paul

    C L 2 Replies Last reply
    0
    • P prcarp

      First, my apologies for posting this again - it went unanswered in the VB forum so I am trying with a bigger audience here.... I have a VB.NET 2005 application that makes calls to a C/C++ (VC6) DLL and I have that part working fine. The C/C++ DLL makes use of callback functions to let the VB application 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. For the short term, I made a string showing the hexadecimal values of the byte array and passed the string from the C/C++ library back up to VB; that works fine for now.... Thanks in advance, Paul

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      have you tried using an IntPtr on the VB side ? CallbackHandler(ByVal dataPtr as IntPtr, ByVal len as Integer) then, Marshall the data into your VB objects...

      image processing toolkits | batch image processing | blogging

      1 Reply Last reply
      0
      • P prcarp

        First, my apologies for posting this again - it went unanswered in the VB forum so I am trying with a bigger audience here.... I have a VB.NET 2005 application that makes calls to a C/C++ (VC6) DLL and I have that part working fine. The C/C++ DLL makes use of callback functions to let the VB application 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. For the short term, I made a string showing the hexadecimal values of the byte array and passed the string from the C/C++ library back up to VB; that works fine for now.... Thanks in advance, Paul

        L Offline
        L Offline
        lafleon
        wrote on last edited by
        #3

        Hello, Read the article on MSDN: “How to Pass Arrays between Visual Basic and C”. http://support.microsoft.com/kb/207931 Some more links: 1. "Passing an array from VC++ DLL to VB", by Amol Kakhandki on Code project. http://www.codeproject.com/dll/ctovbarray\_passing.asp 2. http://www.manbu.net/Lib/En/Class5/Sub7/1/23.asp Regards

        P 1 Reply Last reply
        0
        • L lafleon

          Hello, Read the article on MSDN: “How to Pass Arrays between Visual Basic and C”. http://support.microsoft.com/kb/207931 Some more links: 1. "Passing an array from VC++ DLL to VB", by Amol Kakhandki on Code project. http://www.codeproject.com/dll/ctovbarray\_passing.asp 2. http://www.manbu.net/Lib/En/Class5/Sub7/1/23.asp Regards

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

          Thanks! Everyone has been a great help and I have the code working now.

          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