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